unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#14350: 24.3; octave mode comment indentation
@ 2013-05-05 15:17 Leo Liu
  2013-05-10  1:29 ` Leo Liu
  0 siblings, 1 reply; 7+ messages in thread
From: Leo Liu @ 2013-05-05 15:17 UTC (permalink / raw)
  To: 14350

Hello Stefan,

Some user from the Octave community has noticed the following change:

x = 12;                         # abc abc abc abc abc abc abc abc abc
                                # abc abc abc

If you TAB in the second comment line, that line will be moved to column
0.

I tested the example in emacs 22.1 and the second comment is supposed to
be aligned to a certain column (similar to ; and ;; in lisp-mode). Will
you be able to bend smie to do this? Thanks.

Leo





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

* bug#14350: 24.3; octave mode comment indentation
  2013-05-05 15:17 bug#14350: 24.3; octave mode comment indentation Leo Liu
@ 2013-05-10  1:29 ` Leo Liu
  2013-05-10 19:57   ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Leo Liu @ 2013-05-10  1:29 UTC (permalink / raw)
  To: 14350

On 2013-05-05 23:17 +0800, Leo Liu wrote:
> x = 12;                         # abc abc abc abc abc abc abc abc abc
>                                 # abc abc abc

matlab.el also does the comment alignment well. Stefan, do you think
this is possible to do with smie?

Leo





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

* bug#14350: 24.3; octave mode comment indentation
  2013-05-10  1:29 ` Leo Liu
@ 2013-05-10 19:57   ` Stefan Monnier
  2013-05-11  2:04     ` Leo Liu
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2013-05-10 19:57 UTC (permalink / raw)
  To: Leo Liu; +Cc: 14350

>> x = 12;                         # abc abc abc abc abc abc abc abc abc
>>                                 # abc abc abc
> matlab.el also does the comment alignment well. Stefan, do you think
> this is possible to do with smie?

Of course.  In the very worst case you can change (buffer-locally)
smie-indent-functions to add any ad-hoc rule.
But maybe this can be fixed globally in smie-indent-comment.


        Stefan





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

* bug#14350: 24.3; octave mode comment indentation
  2013-05-10 19:57   ` Stefan Monnier
@ 2013-05-11  2:04     ` Leo Liu
  2013-05-11  3:35       ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Leo Liu @ 2013-05-11  2:04 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 14350

On 2013-05-11 03:57 +0800, Stefan Monnier wrote:
> Of course.  In the very worst case you can change (buffer-locally)
> smie-indent-functions to add any ad-hoc rule.
> But maybe this can be fixed globally in smie-indent-comment.

Thanks for the comment (did I just use a pun?).

Unfortunately I have little knowledge of smie so I have to rely on
others to get this to behave. Thanks in advance.

Leo





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

* bug#14350: 24.3; octave mode comment indentation
  2013-05-11  2:04     ` Leo Liu
@ 2013-05-11  3:35       ` Stefan Monnier
  2013-05-11  5:14         ` Leo Liu
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2013-05-11  3:35 UTC (permalink / raw)
  To: Leo Liu; +Cc: 14350

>> Of course.  In the very worst case you can change (buffer-locally)
>> smie-indent-functions to add any ad-hoc rule.
>> But maybe this can be fixed globally in smie-indent-comment.
> Thanks for the comment (did I just use a pun?).
> Unfortunately I have little knowledge of smie so I have to rely on
> others to get this to behave. Thanks in advance.

No, no, you don't.  smie-indent-functions is just a hook that runs
functions that come up with some indentation choice.  It basically sits
between line-indent-function and smie proper.  You can add your own
function which will not itself need to use anything from smie.
Look at its docstring.


        Stefan





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

* bug#14350: 24.3; octave mode comment indentation
  2013-05-11  3:35       ` Stefan Monnier
@ 2013-05-11  5:14         ` Leo Liu
  2013-05-13 11:15           ` Leo Liu
  0 siblings, 1 reply; 7+ messages in thread
From: Leo Liu @ 2013-05-11  5:14 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 14350

On 2013-05-11 11:35 +0800, Stefan Monnier wrote:
> No, no, you don't.  smie-indent-functions is just a hook that runs
> functions that come up with some indentation choice.  It basically sits
> between line-indent-function and smie proper.  You can add your own
> function which will not itself need to use anything from smie.
> Look at its docstring.

I intend to fix the bug with this patch. Comments?

diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el
index 780bb2f5..5d8186f5 100644
--- a/lisp/progmodes/octave.el
+++ b/lisp/progmodes/octave.el
@@ -414,6 +414,13 @@ (defun octave-smie-rules (kind token)
        ;; (if (smie-parent-p "switch") 4)
        0))))
 
+(defun octave-indent-comment ()
+  "A function for `smie-indent-functions'."
+  (save-excursion
+    (back-to-indentation)
+    (when (and (looking-at-p "\\s<") (not (looking-at-p "\\s<\\s<")))
+      (comment-choose-indent))))
+
 \f
 (defvar octave-font-lock-keywords
   (list
@@ -488,6 +495,7 @@ (define-derived-mode octave-mode prog-mode "Octave"
               :forward-token  #'octave-smie-forward-token
               :backward-token #'octave-smie-backward-token)
   (setq-local smie-indent-basic 'octave-block-offset)
+  (add-hook 'smie-indent-functions #'octave-indent-comment nil t)
 
   (setq-local smie-blink-matching-triggers
               (cons ?\; smie-blink-matching-triggers))





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

* bug#14350: 24.3; octave mode comment indentation
  2013-05-11  5:14         ` Leo Liu
@ 2013-05-13 11:15           ` Leo Liu
  0 siblings, 0 replies; 7+ messages in thread
From: Leo Liu @ 2013-05-13 11:15 UTC (permalink / raw)
  To: 14350-done

Fixed in trunk.






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

end of thread, other threads:[~2013-05-13 11:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-05 15:17 bug#14350: 24.3; octave mode comment indentation Leo Liu
2013-05-10  1:29 ` Leo Liu
2013-05-10 19:57   ` Stefan Monnier
2013-05-11  2:04     ` Leo Liu
2013-05-11  3:35       ` Stefan Monnier
2013-05-11  5:14         ` Leo Liu
2013-05-13 11:15           ` Leo Liu

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).