Permalink
Browse files

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...
1 parent b8784e1 commit 14948d45dee31344c8c9f103cc89889e3f9ad98b @andreas-roehler andreas-roehler committed Jan 15, 2013
Showing with 90 additions and 8 deletions.
  1. +9 −4 NEWS
  2. +19 −0 README
  3. +62 −4 python-mode.el
View
@@ -11,11 +11,16 @@ New in version 6.1.1
py-comment-class, py-comment-def-or-class,
py-comment-statement
-- when `py-tab-shifts-region-p' is `t',
- TAB will indent/cycle the region, not just the current line.
+- boolean `py-set-fill-column-p'
+ If `t', enables use Python specific `fill-column' according to
+ `py-docstring-fill-column', default is 72
+ and `py-comment-fill-column, default is 79
-- when `py-tab-indents-region-p' is `t',
- When first TAB doesn't shift, `indent-region' is called
+- boolean `py-tab-shifts-region-p'
+ when `t', TAB will indent/cycle the region, not just the current line.
+
+- boolean `py-tab-indents-region-p'
+ when `t', when first TAB doesn't shift, `indent-region' is called
- command from RET customizable via `py-return-key':
`py-newline-and-indent', `newline' or `py-newline-and-dedent'
View
@@ -133,3 +133,22 @@ selecting the corresponding beginning or end
new "py-up...", "py-down..." jump regexp-based to the
next element in buffer.
Listed in PyMenu.
+
+;;;;;;;;;
+
+Customize boolean `py-set-fill-column-p'
+
+If `t', enables use Python specific `fill-column' according to
+
+`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
+
+
+
+
+
View
@@ -158,6 +158,37 @@ See also `py-no-completion-calls-dabbrev-expand-p'"
:type 'boolean
:group 'python-mode)
+(defcustom py-set-fill-column-p nil
+ "If python-mode should set fill-column
+
+according values in `py-comment-fill-column' and `py-docstring-fill-column'.
+Default is nil"
+
+ :type 'boolean
+ :group 'python-mode)
+
+(defcustom py-autofill-timer-delay 1
+ "Delay when idle before functions ajusting `py-docstring-fill-column' resp. `py-comment-fill-column' are called. "
+ :type 'integer
+
+ :group 'python-mode)
+
+(defcustom py-docstring-fill-column 72
+ "Value of `fill-column' to use when filling a docstring.
+Any non-integer value means do not use a different value of
+`fill-column' when filling docstrings."
+ :type '(choice (integer)
+ (const :tag "Use the current `fill-column'" t))
+ :group 'python-mode)
+
+(defcustom py-comment-fill-column 79
+ "Value of `fill-column' to use when filling a comment.
+Any non-integer value means do not use a different value of
+`fill-column' when filling docstrings."
+ :type '(choice (integer)
+ (const :tag "Use the current `fill-column'" t))
+ :group 'python-mode)
+
(defcustom py-fontify-shell-buffer-p nil
"If code in Python shell should be highlighted as in script buffer.
@@ -11867,6 +11898,12 @@ Run pdb under GUD"]
("Modes"
:help "Toggle useful modes like `highlight-indentation'"
+ ["Auto-fill mode"
+ (setq py-set-fill-column-p
+ (not py-set-fill-column-p))
+ :help "Set Python specific `fill-column' according to `py-docstring-fill-column' and `py-comment-fill-column' "
+ :style toggle :selected py-set-fill-column-p]
+
["Toggle use-current-dir-when-execute-p"
(setq py-use-current-dir-when-execute-p
(not py-use-current-dir-when-execute-p))
@@ -11952,14 +11989,12 @@ indent-width will be guessed from current major-mode"
)
-
["Electric comment "
(setq py-electric-comment-p
(not py-electric-comment-p))
:help "If \"#\" should call `py-electric-comment'\. Default is `nil'\. "
:style toggle :selected py-electric-comment-p]
-
)
("Help"
@@ -13170,6 +13205,10 @@ Mark innermost definition at point"]
:help "`py-mark-def-or-class'
Mark innermost definition at point"]
+ ["Mark comment" py-mark-comment
+ :help "`py-mark-comment'
+Mark commented section at point"]
+
)
("Copy ... "
@@ -13332,7 +13371,6 @@ Shift block-or-clause left. "]
)
-
"-"
("Block ... "
["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
)
map))
-
(defvaralias 'py-mode-map 'python-mode-map)
;;; Abbrevs
@@ -19003,6 +19040,24 @@ bottom) of the trackback stack is encountered."
;; (add-to-list 'interpreter-mode-alist (cons (purecopy "python") 'python-mode))
;; (add-to-list 'interpreter-mode-alist (cons (purecopy "jython") 'jython-mode))
+(defun py-set-auto-fill-values ()
+ "Internal use by `py-run-auto-fill-timer'"
+ (let ((pps (syntax-ppss)))
+ (cond ((and (nth 4 pps)(numberp py-comment-fill-column))
+ (set (make-local-variable 'fill-column) py-comment-fill-column))
+ ((and (nth 3 pps)(numberp py-docstring-fill-column))
+ (set (make-local-variable 'fill-column) py-docstring-fill-column))
+ (t (set (make-local-variable 'fill-column) py-fill-column-orig)))))
+
+(defun py-run-auto-fill-timer ()
+ "Set fill-column to values of `py-docstring-fill-column' resp. to `py-comment-fill-column' according to environment. "
+ (when py-set-fill-column-p
+ (unless py-autofill-timer
+ (setq py-autofill-timer
+ (run-with-idle-timer
+ py-autofill-timer-delay t
+ 'py-set-auto-fill-values)))))
+
;;;
(define-derived-mode inferior-python-mode comint-mode "Inferior Python"
"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
(t
(add-hook 'completion-at-point-functions
'py-shell-complete nil 'local)))
+ (if py-set-fill-column-p
+ (add-hook 'python-mode-hook 'py-run-auto-fill-timer)
+ (remove-hook 'python-mode-hook 'py-run-auto-fill-timer))
(when (and py-imenu-create-index-p
(fboundp 'imenu-add-to-menubar)
(ignore-errors (require 'imenu)))

0 comments on commit 14948d4

Please sign in to comment.