Georg Bauhaus <[email protected]> writes:

>> Am 28.10.2015 um 17:52 schrieb Stephen Leake 
>> <[email protected]>:
>> 
>> Hmm. This is using wisi-comment-indent in a place I had not anticipated.
>> 
>> (...)
>> So what do you want wisi-comment-indent to do in this case (besides not
>> signal an error)?
>
> Adding to the report: I also see the signal in places like these
> (on the first line only):
>
>    procedure Run_Me with
>      Pre =>
>        --  Be sure to have initialized `Stateful` before calling this.

Hmm. This is a different case; it is indenting the first line of the
comment instead of inserting a comment.

In this case, `comment-dwim' calls `comment-indent', which says "indent
to `comment-column'. Which is certainly _not_ what I would expect. And
it's not what the code actually does; it calls
`comment-indent-function', and if that returns nil, it calls
`indent-according-to-mode'. So we can get the result we want (which is
to indent relative to the preceding code).

> Given this is effected by M-;, maybe what is to be done is dictated by
> usual expectations?
> IIUC, that would be as per   (info "(emacs)Comment Commands")

In this case, that is:

    Insert or realign comment on current line

Which is not helpful. In particular, the actual implementation does
_not_ call "align", so "realign" is simply wrong; it should say
"re-indent".


Try this (it passes the new tests I've added based on your report):

(defun wisi-comment-indent ()
  "For `comment-indent-function'. Indent single line comment to
the comment on the previous line."
  (or
   (save-excursion
     (forward-comment -1) ;; See if there is a preceding comment line.
     (when (looking-at comment-start)
       (current-column)))
     
   ;; Probably called from `comment-dwim'; either to insert a new
   ;; comment, or to indent the first line of an existing one.  In
   ;; either case, the comment may be after code on the same line.
   (save-excursion
     (back-to-indentation)
     (if (looking-at comment-start)
         ;; Indenting an existing comment. Return nil, so
         ;; `comment-dwim' will call `indent-according-to-mode'
         nil

       ;; Inserting a new comment at `comment-column'.
       comment-column)
     )))


-- 
-- Stephe

_______________________________________________
Emacs-ada-mode mailing list
[email protected]
http://host114.hostmonster.com/mailman/listinfo/emacs-ada-mode_stephe-leake.org

Reply via email to