all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Christopher J. Madsen" <cjm@cjmweb.net>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 385@debbugs.gnu.org
Subject: bug#385: [PATCH] comment-indent doesn't respect comment-indent-function
Date: Wed, 2 Mar 2016 23:03:37 -0600	[thread overview]
Message-ID: <56D7C5A9.7040007@cjmweb.net> (raw)
In-Reply-To: <87ziukw1re.fsf@gnus.org>

On 2/28/2016 10:59 PM, Lars Ingebrigtsen wrote:
> Is this still an issue in Emacs 25? 

Yes.  I built emacs-25.1.50.1 from 04289d1cd and nothing seems to have
changed.  The fundamental problem is that there's no way for a
comment-indent-function to say "Put the comment here, and I really mean
it."  In some situations, comment-indent will always second-guess the
comment-indent-function.  In particular, it insists on aligning the
comment with a comment on the line above even when that's not what I want.

To reproduce this, load this Perl code:

#! /usr/bin/perl

if (1) {
  if (2) {
    if (3) {
      4;
    } # end 3
  } # end 2
} # end 1

And set comment-indent-function to this function:

(defun cjm-perl-comment-indent ()
  (if (and (bolp) (not (eolp)))
      0                                 ;Existing comment at bol stays
there.
    (save-excursion
      ;; endcol is the minimum column number the comment can start at
      ;; and still leave one space after text already on the line
      (skip-chars-backward " \t")
      (let ((endcol (1+ (current-column))))
        (if (= 1 endcol)                ;Don't leave just one space
            (setq endcol 0))            ;at beginning of line
        (beginning-of-line)
        (cond
         ;; CASE 1: A comment following a solitary closing brace should
         ;; have only one space.
         ((looking-at "[ \t]*}[ \t]*\\($\\|#\\)")
          endcol)
         ;; CASE 2: Align with comment on previous line
         ;; unless that's more than 9 chars before comment-column,
         ;; and leave at least one space (unless starting at bol).
         ((and (= 0 (forward-line -1))
               (looking-at ".*[ \t]\\(#\\)")
               (progn
                 (goto-char (match-beginning 1))
                 (> 10 (- comment-column (current-column)))))
          (max (current-column) endcol))
         ;; CASE 3: indent at comment column except leave at least one
         ;; space (unless at bol)
         (t (max endcol comment-column))
         )))))

Put point on the "end 2" line, hit M-; and the comment will be moved to
align with the "end 3 " comment instead of staying where it was.  Repeat
on the "end 1" line and you'll have

    } # end 3
  }   # end 2
}     # end 1

instead of the original code.

(You don't actually need a comment-indent-function this complex to
reproduce the issue, but this is the actual function I use.)

Sorry for the delay in getting back to you.

-- 
Chris Madsen                                           cjm@cjmweb.net
  --------------------  http://www.cjmweb.net  --------------------






      reply	other threads:[~2016-03-03  5:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-11 17:11 bug#385: [PATCH] comment-indent doesn't respect comment-indent-function Christopher J. Madsen
2008-06-11 18:04 ` Stefan Monnier
2008-06-11 18:59   ` Christopher J. Madsen
2008-06-13 16:47     ` bug#385: [PATCH] comment-indent doesn't respect Stefan Monnier
2017-06-14  4:33   ` bug#385: [PATCH] comment-indent doesn't respect comment-indent-function npostavs
2017-07-06  2:58     ` npostavs
2016-02-29  4:59 ` Lars Ingebrigtsen
2016-03-03  5:03   ` Christopher J. Madsen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56D7C5A9.7040007@cjmweb.net \
    --to=cjm@cjmweb.net \
    --cc=385@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.