bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#19740: 25.0.50; Bad comment indentation by `C-M-q' in `emacs-lisp-mo


From: npostavs
Subject: bug#19740: 25.0.50; Bad comment indentation by `C-M-q' in `emacs-lisp-mode'
Date: Wed, 14 Jun 2017 19:54:08 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux)

# I accidentally tagged this bug instead of #385 before
tags 385 + patch
quit

Drew Adams <drew.adams@oracle.com> writes:

> This is a regression introduced after Emacs 20 (perhaps after 21).
>
> Emacs should not indent the first `;;' comment line here by a space.
> That does no good and interferes with alignment of a multi-line
> comments and multiple separate comments that are on the same level.
>
> (let* ( ;; If FOOBAR then blah the blahdy blah and other blahs if blah,
>        ;; blah, or blah.  Unless, that is, blah, blah, or blah.
>        (the-tatas (bar-bar-toto-babar foo1 foo2 foo3))
>        ...)
>
> In Emacs 20, this is the result - no extra space inserted.  The two
> comment lines, which are logically at the same level, and in this case
> are part of a single multi-line comment, are aligned vertically.
>
> (let* (;; If FOOBAR then blah the blahdy blah and other blahs if blah,
>        ;; blah, or blah.  Unless, that is, blah, blah, or blah.
>        (the-tatas (bar-bar-toto-babar foo1 foo2 foo3))
>        ...)


This was introduced in [1: bdbe3a8995].  I think in most contexts, it
makes sense to put the space, but it definitely looks wrong in a lisp
let.  Here's patch to override the alignment for comments following an
open in paren in lisp modes.  It requires the patch I posted for #385.

>From f314ec8ee3b99bb6adc5ee789ef07b8b834b5c57 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Wed, 14 Jun 2017 00:13:06 -0400
Subject: [PATCH v1] Don't put whitespace between open paren and comment in
 Lisp modes (Bug#19740)

* lisp/emacs-lisp/lisp-mode.el (lisp-comment-indent): If current
line's code ends in open paren, set comment indentation exactly to
column following it.
(lisp-mode-variables): Set `comment-indent-function' to
`lisp-comment-indent'.
---
 lisp/emacs-lisp/lisp-mode.el | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 59db00d5f9..985b7513a3 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -602,6 +602,7 @@ (defun lisp-mode-variables (&optional lisp-syntax 
keywords-case-insensitive
   ;;(set (make-local-variable 'adaptive-fill-mode) nil)
   (setq-local indent-line-function 'lisp-indent-line)
   (setq-local indent-region-function 'lisp-indent-region)
+  (setq-local comment-indent-function #'lisp-comment-indent)
   (setq-local outline-regexp ";;;\\(;* [^ \t\n]\\|###autoload\\)\\|(")
   (setq-local outline-level 'lisp-outline-level)
   (setq-local add-log-current-defun-function #'lisp-current-defun-name)
@@ -735,9 +736,15 @@ (defalias 'common-lisp-mode 'lisp-mode)
 
 (autoload 'lisp-eval-defun "inf-lisp" nil t)
 
-;; May still be used by some external Lisp-mode variant.
-(define-obsolete-function-alias 'lisp-comment-indent
-    'comment-indent-default "22.1")
+(defun lisp-comment-indent ()
+  "Like `comment-indent-default', but don't put space after open paren."
+  (let ((pt (point)))
+    (skip-syntax-backward " ")
+    (if (eq (preceding-char) ?\()
+        (cons (current-column) (current-column))
+      (goto-char pt)
+      (comment-indent-default))))
+
 (define-obsolete-function-alias 'lisp-mode-auto-fill 'do-auto-fill "23.1")
 
 (defcustom lisp-indent-offset nil
-- 
2.11.1


[1: bdbe3a8995]: 2000-09-29 19:11:42 +0000
  (comment-indent-function): Use 0 for ;;; and %%%. (comment-indent): Make sure 
there's a space between code and comment[...]
  
http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=bdbe3a8995c5f1dae126acd4be4872f6af687cd1

reply via email to

[Prev in Thread] Current Thread [Next in Thread]