Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Python specific `fill-column' enabled, lp:1037454

Customize new boolean `py-set-fill-column-p'. If `t', reads
`py-docstring-fill-column', default is 72
and `py-comment-fill-column, default is 79

Comment- and docstring settings might be disabled by
any non-integer value, which means: do not use a
different value of `fill-column' than emacs-wide
  • Loading branch information...
commit 14948d45dee31344c8c9f103cc89889e3f9ad98b 1 parent b8784e1
Andreas Röhler authored January 15, 2013
13  NEWS
@@ -11,11 +11,16 @@ New in version 6.1.1
11 11
   py-comment-class, py-comment-def-or-class,
12 12
   py-comment-statement
13 13
 
14  
-- when `py-tab-shifts-region-p' is `t',
15  
-  TAB will indent/cycle the region, not just the current line.
  14
+- boolean `py-set-fill-column-p'
  15
+  If `t', enables use Python specific `fill-column' according to
  16
+  `py-docstring-fill-column', default is 72
  17
+  and `py-comment-fill-column, default is 79
16 18
 
17  
-- when `py-tab-indents-region-p' is `t',
18  
-  When first TAB doesn't shift, `indent-region' is called
  19
+- boolean `py-tab-shifts-region-p'
  20
+  when `t', TAB will indent/cycle the region, not just the current line.
  21
+
  22
+- boolean `py-tab-indents-region-p' 
  23
+  when `t', when first TAB doesn't shift, `indent-region' is called
19 24
 
20 25
 - command from RET customizable via `py-return-key':
21 26
   `py-newline-and-indent', `newline' or `py-newline-and-dedent'
19  README
@@ -133,3 +133,22 @@ selecting the corresponding beginning or end
133 133
 new "py-up...", "py-down..." jump regexp-based to the 
134 134
 next element in buffer.
135 135
 Listed in PyMenu. 
  136
+
  137
+;;;;;;;;;
  138
+
  139
+Customize boolean `py-set-fill-column-p'
  140
+
  141
+If `t', enables use Python specific `fill-column' according to
  142
+
  143
+`py-docstring-fill-column', default is 72
  144
+
  145
+and `py-comment-fill-column, default is 79
  146
+
  147
+Comment- and docstring settings might be disabled by
  148
+any non-integer value, which means: do not use a
  149
+different value of `fill-column' than emacs-wide
  150
+
  151
+
  152
+
  153
+
  154
+
66  python-mode.el
@@ -158,6 +158,37 @@ See also `py-no-completion-calls-dabbrev-expand-p'"
158 158
   :type 'boolean
159 159
   :group 'python-mode)
160 160
 
  161
+(defcustom py-set-fill-column-p nil
  162
+  "If python-mode should set fill-column
  163
+
  164
+according values in `py-comment-fill-column' and `py-docstring-fill-column'.
  165
+Default is  nil"
  166
+
  167
+  :type 'boolean
  168
+  :group 'python-mode)
  169
+
  170
+(defcustom py-autofill-timer-delay 1
  171
+  "Delay when idle before functions ajusting  `py-docstring-fill-column' resp. `py-comment-fill-column' are called. "
  172
+  :type 'integer
  173
+
  174
+  :group 'python-mode)
  175
+
  176
+(defcustom py-docstring-fill-column 72
  177
+  "Value of `fill-column' to use when filling a docstring.
  178
+Any non-integer value means do not use a different value of
  179
+`fill-column' when filling docstrings."
  180
+  :type '(choice (integer)
  181
+                 (const :tag "Use the current `fill-column'" t))
  182
+  :group 'python-mode)
  183
+
  184
+(defcustom py-comment-fill-column 79
  185
+  "Value of `fill-column' to use when filling a comment.
  186
+Any non-integer value means do not use a different value of
  187
+`fill-column' when filling docstrings."
  188
+  :type '(choice (integer)
  189
+                 (const :tag "Use the current `fill-column'" t))
  190
+  :group 'python-mode)
  191
+
161 192
 (defcustom py-fontify-shell-buffer-p nil
162 193
   "If code in Python shell should be highlighted as in script buffer.
163 194
 
@@ -11867,6 +11898,12 @@ Run pdb under GUD"]
11867 11898
             ("Modes"
11868 11899
              :help "Toggle useful modes like `highlight-indentation'"
11869 11900
 
  11901
+             ["Auto-fill mode"
  11902
+              (setq py-set-fill-column-p
  11903
+                    (not py-set-fill-column-p))
  11904
+              :help "Set Python specific `fill-column' according to `py-docstring-fill-column' and `py-comment-fill-column' "
  11905
+              :style toggle :selected py-set-fill-column-p]
  11906
+
11870 11907
              ["Toggle use-current-dir-when-execute-p"
11871 11908
               (setq py-use-current-dir-when-execute-p
11872 11909
                     (not py-use-current-dir-when-execute-p))
@@ -11952,14 +11989,12 @@ indent-width will be guessed from current major-mode"
11952 11989
 
11953 11990
               )
11954 11991
 
11955  
-
11956 11992
              ["Electric comment "
11957 11993
               (setq py-electric-comment-p
11958 11994
                     (not py-electric-comment-p))
11959 11995
               :help "If \"#\" should call `py-electric-comment'\. Default is `nil'\. "
11960 11996
               :style toggle :selected py-electric-comment-p]
11961 11997
 
11962  
-
11963 11998
              )
11964 11999
 
11965 12000
             ("Help"
@@ -13170,6 +13205,10 @@ Mark innermost definition at point"]
13170 13205
               :help "`py-mark-def-or-class'
13171 13206
 Mark innermost definition at point"]
13172 13207
 
  13208
+             ["Mark comment" py-mark-comment
  13209
+              :help "`py-mark-comment'
  13210
+Mark commented section at point"]
  13211
+
13173 13212
              )
13174 13213
 
13175 13214
             ("Copy ... "
@@ -13332,7 +13371,6 @@ Shift block-or-clause left. "]
13332 13371
 
13333 13372
              )
13334 13373
 
13335  
-
13336 13374
             "-"
13337 13375
             ("Block ... "
13338 13376
              ["Beginning of block" py-beginning-of-block
@@ -14370,7 +14408,6 @@ Optional C-u prompts for options to pass to the Python3.2 interpreter. See `py-p
14370 14408
           )
14371 14409
         map))
14372 14410
 
14373  
-
14374 14411
 (defvaralias 'py-mode-map 'python-mode-map)
14375 14412
 
14376 14413
 ;;; Abbrevs
@@ -19003,6 +19040,24 @@ bottom) of the trackback stack is encountered."
19003 19040
 ;; (add-to-list 'interpreter-mode-alist (cons (purecopy "python") 'python-mode))
19004 19041
 ;; (add-to-list 'interpreter-mode-alist (cons (purecopy "jython") 'jython-mode))
19005 19042
 
  19043
+(defun py-set-auto-fill-values ()
  19044
+  "Internal use by `py-run-auto-fill-timer'"
  19045
+  (let ((pps (syntax-ppss)))
  19046
+    (cond ((and (nth 4 pps)(numberp py-comment-fill-column))
  19047
+           (set (make-local-variable 'fill-column) py-comment-fill-column))
  19048
+          ((and (nth 3 pps)(numberp py-docstring-fill-column))
  19049
+           (set (make-local-variable 'fill-column) py-docstring-fill-column))
  19050
+          (t (set (make-local-variable 'fill-column) py-fill-column-orig)))))
  19051
+
  19052
+(defun py-run-auto-fill-timer ()
  19053
+  "Set fill-column to values of `py-docstring-fill-column' resp. to `py-comment-fill-column' according to environment. "
  19054
+  (when py-set-fill-column-p
  19055
+    (unless py-autofill-timer
  19056
+      (setq py-autofill-timer
  19057
+            (run-with-idle-timer
  19058
+             py-autofill-timer-delay t
  19059
+             'py-set-auto-fill-values)))))
  19060
+
19006 19061
 ;;;
19007 19062
 (define-derived-mode inferior-python-mode comint-mode "Inferior Python"
19008 19063
   "Major mode for interacting with an inferior Python process.
@@ -19138,6 +19193,9 @@ py-beep-if-tab-change\t\tring the bell if `tab-width' is changed
19138 19193
    (t
19139 19194
     (add-hook 'completion-at-point-functions
19140 19195
               'py-shell-complete nil 'local)))
  19196
+  (if py-set-fill-column-p
  19197
+      (add-hook 'python-mode-hook 'py-run-auto-fill-timer)
  19198
+    (remove-hook 'python-mode-hook 'py-run-auto-fill-timer))
19141 19199
   (when (and py-imenu-create-index-p
19142 19200
              (fboundp 'imenu-add-to-menubar)
19143 19201
              (ignore-errors (require 'imenu)))

0 notes on commit 14948d4

Please sign in to comment.
Something went wrong with that request. Please try again.