all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#11090: 24.0.94; Allow customization of inline-comment offset
@ 2012-03-25 16:52 Philipp Haselwarter
  2012-03-25 18:41 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Philipp Haselwarter @ 2012-03-25 16:52 UTC (permalink / raw)
  To: 11090

[-- Attachment #1: Type: text/plain, Size: 462 bytes --]



When I ran pep8 over some python code it indicated that the offset
between code and comments on the same line should be at least two
whitespace characters.
Ref.:
http://www.python.org/dev/peps/pep-0008/#inline-comments


The attached patch allows for `comment-indent' to configure that offset,
that is currently hard-coded to one space, by introducing the new
variable `comment-inline-offset'.

The default behavior remains unchanged.

-- 
Philipp Haselwarter

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-customization-of-the-offset-between-code-and-i.patch --]
[-- Type: text/x-patch, Size: 1818 bytes --]

From 15e86f0b218b7a1bd32426c71bad930208e5606a Mon Sep 17 00:00:00 2001
From: Philipp Haselwarter <philipp.haselwarter@gmx.de>
Date: Sun, 25 Mar 2012 18:32:11 +0200
Subject: [PATCH] Allow customization of the offset between code and
 inline-comments.

* lisp/newcomment.el (comment-inline-offset): New variable.
(comment-indent): Honor comment-inline-offset.
---
 lisp/newcomment.el |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index 40bb36d..c78a3a1 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -270,6 +270,19 @@ makes the comment easier to read.  Default is 1.  nil means 0."
   :group 'comment)
 
 ;;;###autoload
+(defcustom comment-inline-offset 1
+  "Inline comments have to be preceded by at least this many spaces.
+This is usefull when style-conventions require a certain minimal offset.
+Python's PEP8 for example recommends two spaces, so you could do:
+
+\(add-hook 'python-mode-hook
+   (lambda nil (set (make-local-variable 'comment-inline-offset) 2)))
+
+See `comment-padding' for whole-line comments."
+  :type 'integer
+  :group 'comment)
+
+;;;###autoload
 (defcustom comment-multi-line nil
   "Non-nil means `comment-indent-new-line' continues comments.
 That is, it inserts no new terminator or starter.
@@ -687,7 +700,7 @@ If CONTINUE is non-nil, use the `comment-continue' markers if any."
 	  (save-excursion
 	    (skip-chars-backward " \t")
 	    (unless (bolp)
-	      (setq indent (max indent (1+ (current-column))))))
+	      (setq indent (max indent (+ (current-column) comment-inline-offset)))))
 	  ;; If that's different from comment's current position, change it.
 	  (unless (= (current-column) indent)
 	    (delete-region (point) (progn (skip-chars-backward " \t") (point)))
-- 
1.7.9.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#11090: 24.0.94; Allow customization of inline-comment offset
  2012-03-25 16:52 bug#11090: 24.0.94; Allow customization of inline-comment offset Philipp Haselwarter
@ 2012-03-25 18:41 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2012-03-25 18:41 UTC (permalink / raw)
  To: Philipp Haselwarter; +Cc: 11090-done

> The attached patch allows for `comment-indent' to configure that offset,
> that is currently hard-coded to one space, by introducing the new
> variable `comment-inline-offset'.

I think it's a good idea, thank you.
Installed in the `pending' branch, for 24.2.
I also installed the following patch on top of it.


        Stefan


=== modified file 'lisp/newcomment.el'
--- lisp/newcomment.el	2012-03-25 18:37:24 +0000
+++ lisp/newcomment.el	2012-03-25 18:38:46 +0000
@@ -268,7 +268,6 @@
   :type '(choice string integer (const nil))
   :group 'comment)
 
-;;;###autoload
 (defcustom comment-inline-offset 1
   "Inline comments have to be preceded by at least this many spaces.
 This is usefull when style-conventions require a certain minimal offset.
@@ -598,7 +597,7 @@
                    (save-excursion (end-of-line) (current-column)))))
         (other nil)
         (min (save-excursion (skip-chars-backward " \t")
-                             (1+ (current-column)))))
+                             (+ comment-inline-offset (current-column)))))
     ;; Fix up the range.
     (if (< max min) (setq max min))
     ;; Don't move past the fill column.
@@ -698,7 +697,8 @@
 	  (save-excursion
 	    (skip-chars-backward " \t")
 	    (unless (bolp)
-	      (setq indent (max indent (+ (current-column) comment-inline-offset)))))
+	      (setq indent (max indent
+                                (+ (current-column) comment-inline-offset)))))
 	  ;; If that's different from comment's current position, change it.
 	  (unless (= (current-column) indent)
 	    (delete-region (point) (progn (skip-chars-backward " \t") (point)))






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-03-25 18:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-25 16:52 bug#11090: 24.0.94; Allow customization of inline-comment offset Philipp Haselwarter
2012-03-25 18:41 ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.