~python-mode-devs/python-mode/python-mode

« back to all changes in this revision

Viewing changes to devel/fundocu2infoformats.el

  • Committer: Barry Warsaw
  • Date: 2017-02-24 21:38:07 UTC
  • Revision ID: barry@python.org-20170224213807-h762012vx6fgvrve
Move repo to GitLab

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
;;; -*- lexical-binding: t; -*- 
2
 
 
3
 
(defcustom py-devel-directory-out ""
4
 
  "Output directory when developing Python-mode. "
5
 
  :type 'string
6
 
  :group 'python-mode)
7
 
 
8
 
(defcustom py-devel-directory-in ""
9
 
  "Input directory when developing Python-mode. "
10
 
  :type 'string
11
 
  :group 'python-mode)
12
 
 
13
 
(defun python-components-mode-list-actives (&optional directory)
14
 
  "Return a list, which components will be loaded. "
15
 
  (interactive)
16
 
  (let ((directory (or directory default-directory))
17
 
        componentslist)
18
 
    (find-file (concat directory "python-components-mode.el"))
19
 
    (save-restriction
20
 
      (widen)
21
 
      (goto-char (point-min))
22
 
      (while (re-search-forward "^[ \t]*(require '\\([^)]+\\))" nil (quote move) 1)
23
 
        (when (save-match-data
24
 
                (string-match "python-components" (match-string-no-properties 0)))
25
 
          (add-to-list 'componentslist (prin1-to-string (match-string-no-properties 1)))))
26
 
      (dolist (ele componentslist)
27
 
        (find-file (concat directory ele)
28
 
                   (finds (concat ele ".el")))))))
29
 
 
30
 
(defun finds-from-programm ()
31
 
  (let ((directory-in (or (and (not (string= "" py-devel-directory-in)) py-devel-directory-in) default-directory))
32
 
        (directory-out (or (and (not (string= "" py-devel-directory-out)) py-devel-directory-out default-directory)) (concat default-directory "doc"))
33
 
        (erg (buffer-file-name))
34
 
        (buffer (current-buffer)))
35
 
    (message "Lade %s" erg)
36
 
    (find-file erg)
37
 
    (finds buffer directory-in directory-out)))
38
 
 
39
 
(defvar python-mode-el-doku-list (list "autopair/autopair.el" "python-mode.el" "completion/auto-complete-pycomplete.el" "completion/company-pycomplete.el" "completion/pycomplete.el" "pymacs.el" "extensions/py-smart-operator.el"))
40
 
 
41
 
(defun finds-alle ()
42
 
  "Write doku for files listet in python-mode-el-doku-list. "
43
 
  (interactive)
44
 
  (dolist (ele python-mode-el-doku-list)
45
 
    (when
46
 
        (and (load (concat "~/arbeit/emacs/python-modes/python-mode/" ele))
47
 
             (find-file (concat "~/arbeit/emacs/python-modes/python-mode/" ele)))
48
 
      (finds))))
49
 
 
50
 
(defun variable-docu (&optional buffer directory-in directory-out)
51
 
  "Writes all variable in BUFFER alongside with their documentation into directory \"doc\" as \*.org and \*rst file ."
52
 
  (interactive)
53
 
  (variables-prepare "docu"))
54
 
 
55
 
(defun variables-base-docu (oldbuf orgname reSTname directory-in directory-out)
56
 
  (save-restriction
57
 
    (let ((suffix (file-name-nondirectory (buffer-file-name)))
58
 
          variableslist)
59
 
      ;; (widen)
60
 
      (goto-char (point-min))
61
 
      ;; (eval-buffer)
62
 
      (while (and (not (eobp))(re-search-forward "^(defvar [[:alpha:]]\\|^(defcustom [[:alpha:]]\\|^(defconst [[:alpha:]]" nil t 1))
63
 
        (let* ((name (symbol-at-point))
64
 
               (docu (documentation-property name 'variable-documentation)))
65
 
                         ;; (documentation-property alias 'variable-documentation))))
66
 
          ;; (docu (get 'variable-documentation name)))
67
 
          (if docu
68
 
              (add-to-list 'variableslist (cons (prin1-to-string name) docu))
69
 
            (message "don't see docu string for %s" (prin1-to-string name))))
70
 
        ;; (add-to-list 'variableslist (list (match-string-no-properties 0)))
71
 
 
72
 
        (forward-line 1))
73
 
      (setq variableslist (nreverse variableslist))
74
 
;;       (with-temp-buffer
75
 
;;         (switch-to-buffer (current-buffer))
76
 
;;         (insert (concat ";; a list of " suffix " variables
77
 
;; \(setq " (replace-regexp-in-string "\\." "-" suffix) "-variables (quote "))
78
 
;;         (insert (prin1-to-string variableslist))
79
 
;;         (insert "))"))
80
 
        ;; (eval-buffer)
81
 
      (with-temp-buffer
82
 
        ;; org
83
 
        ;; (insert (concat (capitalize (substring oldbuf 0 (string-match "\." oldbuf))) " variables" "\n\n"))
84
 
        ;; (insert (concat suffix " variables\n\n"))
85
 
        (insert "Python-mode variables\n\n")
86
 
        (switch-to-buffer (current-buffer))
87
 
        (dolist (ele variableslist)
88
 
          (if (string-match "^;;; " (car ele))
89
 
              (unless (or (string-match "^;;; Constants\\|^;;; Commentary\\|^;;; Code\\|^;;; Macro definitions\\|^;;; Customization" (car ele)))
90
 
 
91
 
                (insert (concat (replace-regexp-in-string "^;;; " "* " (car ele)) "\n")))
92
 
            (insert (concat "\n** "(car ele) "\n"))
93
 
            (insert (concat "   " (cdr ele) "\n\n")))
94
 
        (richten)
95
 
        (sit-for 0.1)
96
 
        (write-file (concat directory-out "variables-" orgname))
97
 
        (find-file (concat directory-out "variables-" orgname))))
98
 
 
99
 
      (with-temp-buffer
100
 
        ;; reST
101
 
        (insert "Python-mode variables\n\n")
102
 
        ;; (insert (concat (make-string (length (concat (substring oldbuf 0 (string-match "\." oldbuf)) " variables")) ?\=) "\n\n"))
103
 
        (insert "====================\n\n")
104
 
        (dolist (ele variableslist)
105
 
          (insert (concat "\n" (car ele) "\n"))
106
 
          (insert (concat (make-string (length (car ele)) ?\-) "\n"))
107
 
          (insert (concat (cdr ele) "\n\n")))
108
 
        (richten)
109
 
        (sit-for 0.1)
110
 
        (write-file (concat directory-out "variables-" reSTname))
111
 
        (find-file (concat directory-out "variables-" reSTname))))))
112
 
 
113
 
(defun finds (&optional buffer directory-in directory-out)
114
 
  "Writes all commands in BUFFER alongside with their documentation into directory \"doc\" as \*.org and \*rst file ."
115
 
  (interactive)
116
 
  (let* ((oldbuf (buffer-name (or buffer (current-buffer))))
117
 
         ;; (file (buffer-file-name))
118
 
         (orgname (concat (substring oldbuf 0 (string-match "\\." oldbuf)) ".org"))
119
 
         (reSTname (concat (substring oldbuf 0 (string-match "\\." oldbuf)) ".rst"))
120
 
         (directory-in (or directory-in (and (not (string= "" py-devel-directory-in)) py-devel-directory-in) default-directory))
121
 
         (directory-out (or directory-out (expand-file-name finds-directory-out))))
122
 
    (finds-base oldbuf orgname reSTname directory-in directory-out)))
123
 
 
124
 
(defun finds-base (oldbuf orgname reSTname directory-in directory-out)
125
 
  (save-restriction
126
 
    (let ((suffix (file-name-nondirectory (buffer-file-name)))
127
 
          commandslist)
128
 
      ;; (widen)
129
 
      (goto-char (point-min))
130
 
      ;; (eval-buffer)
131
 
      (while (and (not (eobp))(re-search-forward "^(defun [[:alpha:]]\\|^;;; .+" nil t 1)) ;
132
 
                                                     (when (save-match-data (commandp (symbol-at-point)))
133
 
                                                       (let* ((name (symbol-at-point))
134
 
                                                              (docu (documentation name)))
135
 
                                                         (if docu
136
 
                                                             (add-to-list 'commandslist (cons (prin1-to-string name) docu))
137
 
                                                           (message "don't see docu string for %s" (prin1-to-string name)))))
138
 
                                                     ;; (add-to-list 'commandslist (list (match-string-no-properties 0)))
139
 
 
140
 
                                                     (forward-line 1))
141
 
      (setq commandslist (nreverse commandslist))
142
 
      (with-temp-buffer
143
 
        (switch-to-buffer (current-buffer))
144
 
        (insert (concat ";; a list of " suffix " commands
145
 
\(setq " (replace-regexp-in-string "\\." "-" suffix) "-commands (quote "))
146
 
        (insert (prin1-to-string commandslist))
147
 
        (insert "))")
148
 
        (eval-buffer))
149
 
      (with-temp-buffer
150
 
        ;; org
151
 
        ;; (insert (concat (capitalize (substring oldbuf 0 (string-match "\." oldbuf))) " commands" "\n\n"))
152
 
        (insert (concat suffix " commands\n\n"))
153
 
        (dolist (ele commandslist)
154
 
          (if (string-match "^;;; " (car ele))
155
 
              (unless (or (string-match "^;;; Constants\\|^;;; Commentary\\|^;;; Code\\|^;;; Macro definitions\\|^;;; Customization" (car ele)))
156
 
 
157
 
                (insert (concat (replace-regexp-in-string "^;;; " "* " (car ele)) "\n")))
158
 
            (insert (concat "** "(car ele) "\n"))
159
 
            (insert (concat "   " (cdr ele) "\n\n"))))
160
 
        (write-file (concat directory-out "commands-" orgname))
161
 
        (find-file (concat directory-out "commands-" orgname)))
162
 
      (with-temp-buffer
163
 
        ;; reST
164
 
        (insert "Commands\n\n")
165
 
        ;; (insert (concat (make-string (length (concat (substring oldbuf 0 (string-match "\." oldbuf)) " commands")) ?\=) "\n\n"))
166
 
        (insert "====================\n\n")
167
 
        (dolist (ele commandslist)
168
 
          (insert (concat (car ele) "\n"))
169
 
          (insert (concat (make-string (length (car ele)) ?\-) "\n"))
170
 
          (insert (concat (cdr ele) "\n\n")))
171
 
        (write-file (concat directory-out "commands-" reSTname))
172
 
        (find-file (concat directory-out "commands-" reSTname))))))
173
 
 
174
 
(defun write-defcustom-docus (&optional buffer directory-in directory-out)
175
 
  "Writes all customizable variables w/ documentation into directory \"doc\" as \*.org and \*rst file ."
176
 
  (interactive)
177
 
  (let* ((oldbuf (buffer-name (or buffer (current-buffer))))
178
 
         ;; (file (buffer-file-name))
179
 
         (orgname (concat (substring oldbuf 0 (string-match "\\." oldbuf)) ".org"))
180
 
         (reSTname (concat (substring oldbuf 0 (string-match "\\." oldbuf)) ".rst"))
181
 
         (directory-in (or directory-in (and (not (string= "" py-devel-directory-in)) py-devel-directory-in) default-directory))
182
 
         (directory-out (or directory-out (expand-file-name finds-directory-out))))
183
 
    (defcustom-docu-base oldbuf orgname reSTname directory-in directory-out)))
184
 
 
185
 
(defun defcustom-docu-base (oldbuf orgname reSTname directory-in directory-out)
186
 
  (save-restriction
187
 
    (let ((suffix (file-name-nondirectory (buffer-file-name)))
188
 
          varslist last)
189
 
      (goto-char (point-min))
190
 
      (while (and (not (eobp))(re-search-forward "^(defcustom [[:alpha:]]" nil t 1))
191
 
        (if (save-match-data (boundp (symbol-at-point)))
192
 
            (let* ((name (variable-at-point))
193
 
                   (docu
194
 
                    (or (documentation-property
195
 
                         name 'variable-documentation)
196
 
                        (documentation-property
197
 
                         alias 'variable-documentation))))
198
 
              (unless docu (message "don't see docu string for %s" (prin1-to-string name)))
199
 
              (add-to-list 'varslist (cons (prin1-to-string name) docu))
200
 
              (forward-line 1))
201
 
          (add-to-list 'varslist (list (match-string-no-properties 0)))))
202
 
      (setq varslist (nreverse varslist))
203
 
      (with-temp-buffer
204
 
        ;; (switch-to-buffer (current-buffer))
205
 
        (insert (concat suffix " variables\n\n"))
206
 
        (dolist (ele varslist)
207
 
          (insert (concat "** "(car ele) "\n"))
208
 
          (insert (concat "   " (cdr ele) "\n\n"))
209
 
          (setq last (point)))
210
 
        (goto-char last)
211
 
        (push-mark)
212
 
        ;; (delete-region (point) (goto-char (point-max)))
213
 
        (delete-region (point)(point-max))
214
 
        (org-mode)
215
 
        (push-mark)
216
 
        (goto-char (point-min))
217
 
        (indent-region (point-min) (point-max) )
218
 
        (write-file (concat directory-out "variables-" orgname))
219
 
        (find-file (concat directory-out "variables-" orgname)))
220
 
      (with-temp-buffer
221
 
        ;; reST
222
 
        (insert "Variables\n\n")
223
 
        ;; (insert (concat (make-string (length (concat (substring oldbuf 0 (string-match "\." oldbuf)) " commands")) ?\=) "\n\n"))
224
 
        (insert "====================\n\n")
225
 
        (dolist (ele varslist)
226
 
          (insert (concat (car ele) "\n"))
227
 
          (insert (concat (make-string (length (car ele)) ?\-) "\n"))
228
 
          (insert (concat (cdr ele) "\n\n")))
229
 
        (write-file (concat directory-out "variables-" reSTname))
230
 
        (find-file (concat directory-out "variables-" reSTname))
231
 
      ))))
232
 
 
233
 
(defun py-variables-unused (&optional buffer directory-in directory-out)
234
 
  "Report unused variables. "
235
 
  (interactive)
236
 
  (variables-prepare "unused"))
237
 
 
238
 
(defun variables-prepare (kind)
239
 
  "Used by variable-finds, variable-states. "
240
 
  (let* ((oldbuf (buffer-name (or buffer (current-buffer))))
241
 
         ;; (file (buffer-file-name))
242
 
         (orgname (concat (substring oldbuf 0 (string-match "\\." oldbuf)) ".org"))
243
 
         (reSTname (concat (substring oldbuf 0 (string-match "\\." oldbuf)) ".rst"))
244
 
         (directory-in default-directory)
245
 
         (directory-out (or directory-out (expand-file-name finds-directory-out)))
246
 
         (command (concat "variables-base-" kind)))
247
 
    (funcall (intern-soft command) oldbuf orgname reSTname directory-in directory-out)))
248
 
 
249
 
(defun variables-base-unused (oldbuf orgname reSTname directory-in directory-out)
250
 
  (save-restriction
251
 
    (let ((suffix (file-name-nondirectory (buffer-file-name)))
252
 
          variableslist)
253
 
      ;; (widen)
254
 
      (goto-char (point-min))
255
 
      ;; (eval-buffer)
256
 
      (while (and (not (eobp))(re-search-forward "^(defvar [[:alpha:]]\\|^(defcustom [[:alpha:]]\\|^(defconst [[:alpha:]]" nil t 1))
257
 
        (let* ((name (symbol-at-point)))
258
 
          (unless
259
 
              (or (eq name 'py-menu)
260
 
                  (eq name 'python-mode-map)
261
 
                  (string-match "syntax-table" (prin1-to-string name))
262
 
                  (save-excursion
263
 
                    (re-search-forward (concat "\\_<" (prin1-to-string name) "\\_>") nil t 1)))
264
 
            (add-to-list 'variableslist (prin1-to-string name))))
265
 
        (forward-line 1))
266
 
      (setq variableslist (nreverse variableslist))
267
 
      ;; (with-temp-buffer
268
 
      (set-buffer (get-buffer-create "Unused-Python-mode-variables.txt"))
269
 
      (erase-buffer)
270
 
      ;; org
271
 
      (insert "Unused python-mode variables\n\n")
272
 
      (switch-to-buffer (current-buffer))
273
 
      (dolist (ele variableslist)
274
 
        (insert (concat ele "\n"))
275
 
        (sit-for 0.01))
276
 
      (sit-for 0.01)
277
 
      )))
278
 
 
279
 
(defun functions-list-base (oldbuf orgname reSTname directory-in directory-out)
280
 
  (save-restriction
281
 
    (let ((suffix (file-name-nondirectory (buffer-file-name)))
282
 
          functionslist)
283
 
      ;; (widen)
284
 
      (goto-char (point-min))
285
 
      ;; (eval-buffer)
286
 
      (while (and (not (eobp))(re-search-forward "^(defun [[:alpha:]]+" nil t 1)) ;
287
 
        (unless (save-match-data (commandp (symbol-at-point)))
288
 
          (let* ((name (symbol-at-point)))
289
 
            (add-to-list 'functionslist name)))
290
 
        (forward-line 1))
291
 
      (set-buffer (get-buffer-create "Unused-Python-mode-functions.txt"))
292
 
      (erase-buffer)
293
 
      ;; org
294
 
      (insert "Unused python-mode functions\n\n")
295
 
      (switch-to-buffer (current-buffer))
296
 
      (dolist (ele functionslist)
297
 
        (insert (concat (prin1-to-string ele) "\n"))
298
 
        (sit-for 0.01))
299
 
      (sit-for 0.01))))
300
 
 
301
 
(defun py-functions-unused (&optional buffer directory-in directory-out)
302
 
  "Report unused functions. "
303
 
  (interactive)
304
 
  (functions-prepare "unused"))
305
 
 
306
 
(defun functions-prepare (kind)
307
 
  "Used by variable-finds, variable-states. "
308
 
  (let* ((oldbuf (buffer-name (or buffer (current-buffer))))
309
 
         ;; (file (buffer-file-name))
310
 
         (orgname (concat (substring oldbuf 0 (string-match "\\." oldbuf)) ".org"))
311
 
         (reSTname (concat (substring oldbuf 0 (string-match "\\." oldbuf)) ".rst"))
312
 
         (directory-in default-directory)
313
 
         (directory-out (or directory-out (expand-file-name finds-directory-out)))
314
 
         (command (concat "functions-base-" kind)))
315
 
    (funcall (intern-soft command) oldbuf orgname reSTname directory-in directory-out)))
316
 
 
317
 
(defun functions-base-unused (oldbuf orgname reSTname directory-in directory-out)
318
 
  (save-restriction
319
 
    (let ((suffix (file-name-nondirectory (buffer-file-name)))
320
 
          functionslist name)
321
 
      ;; (widen)
322
 
      (goto-char (point-min))
323
 
      ;; (eval-buffer)
324
 
      (while (and (not (eobp))(re-search-forward "^(defun [[:alpha:]]+" nil t 1)) ;
325
 
        (unless (or (save-match-data (commandp (setq name (symbol-at-point))))
326
 
                    (save-excursion
327
 
                      (goto-char (point-min)) 
328
 
                      (re-search-forward (concat "\\_<\(" (prin1-to-string name) "\\_>") nil t 1)))
329
 
          (add-to-list 'functionslist name))
330
 
        (forward-line 1))
331
 
      (set-buffer (get-buffer-create "Unused-Python-mode-functions.txt"))
332
 
      (erase-buffer)
333
 
      ;; org
334
 
      (insert "Unused python-mode functions\n\n")
335
 
      (switch-to-buffer (current-buffer))
336
 
      (dolist (ele functionslist)
337
 
        (insert (concat (prin1-to-string ele) "\n"))
338
 
        (sit-for 0.01))
339
 
      (sit-for 0.01))))
340
 
 
341
 
(defun py-all-docu ()
342
 
  "Write documentations commands and user-defined variables "
343
 
  (interactive)
344
 
  (find-file "~/arbeit/emacs/python-modes/python-mode/python-mode.el")
345
 
  (eval-buffer)
346
 
  (sit-for 0.1 t) 
347
 
  (finds)
348
 
  (sit-for 0.1 t)
349
 
  (write-defcustom-docus))
350
 
  
351