* align-regexp problem when called from lisp code
@ 2013-08-08 10:34 Luca Ferrari
2013-08-08 11:32 ` Tassilo Horn
0 siblings, 1 reply; 8+ messages in thread
From: Luca Ferrari @ 2013-08-08 10:34 UTC (permalink / raw
To: help-gnu-emacs
Hi all,
if I use (align-regexp) interactively with a region marked all works
as expected, but if I call it from the following piece of lisp:
(defun fluca1978/align-assignments ()
(interactive )
(let ( (line-moving-increment) )
(align-regexp (point) (mark) "=" )
(deactivate-mark) ) )
I got the following stack trace:
Debugger entered--Lisp error: (error "Marker does not point anywhere")
align-areas(((#<marker (moves after insertion) in no buffer> .
#<marker (moves after insertion) in no buffer>) (#<marker (moves after
insertion) in no buffer> . #<marker (moves after insertion) in no
buffer>) (#<marker (moves after insertion) in no buffer> . #<marker
(moves after insertion) in no buffer>) (#<marker (moves after
insertion) in no buffer> . #<marker (moves after insertion) in no
buffer>) (#<marker (moves after insertion) in no buffer> . #<marker
(moves after insertion) in no buffer>) (#<marker (moves after
insertion) in no buffer> . #<marker (moves after insertion) in no
buffer>) (#<marker (moves after insertion) in no buffer> . #<marker
(moves after insertion) in no buffer>) (#<marker (moves after
insertion) in no buffer> . #<marker (moves after insertion) in no
buffer>) (#<marker (moves after insertion) in no buffer> . #<marker
(moves after insertion) in no buffer>) (#<marker (moves after
insertion) in no buffer> . #<marker (moves after insertion) in no
buffer>)) (1) (nil (regexp . "=") (group . 1) (bogus) (spacing . 1)
(repeat)) nil)
align-region(5171 5775 entire ((nil (regexp . "=") (group . 1)
(bogus) (spacing . 1) (repeat))) nil nil)
align-regexp(5171 5775 "=")
(let ((line-moving-increment)) (align-regexp (point) (mark) "=")
(deactivate-mark))
fluca1978/align-assignments()
call-interactively(fluca1978/align-assignments t nil)
execute-extended-command(nil)
call-interactively(execute-extended-command nil nil)
What am I missing?
Thanks,
Luca
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: align-regexp problem when called from lisp code
2013-08-08 10:34 align-regexp problem when called from lisp code Luca Ferrari
@ 2013-08-08 11:32 ` Tassilo Horn
2013-08-08 11:57 ` Luca Ferrari
0 siblings, 1 reply; 8+ messages in thread
From: Tassilo Horn @ 2013-08-08 11:32 UTC (permalink / raw
To: Luca Ferrari; +Cc: help-gnu-emacs
Luca Ferrari <fluca1978@infinito.it> writes:
> if I use (align-regexp) interactively with a region marked all works
> as expected, but if I call it from the following piece of lisp:
>
> (defun fluca1978/align-assignments ()
> (interactive )
> (let ( (line-moving-increment) )
> (align-regexp (point) (mark) "=" )
> (deactivate-mark) ) )
You should make it explicit that the command wants a region using the
interactive spec. Also, `align-regexp' mangles the regexp given to it a
bit. I guess this does what you want:
--8<---------------cut here---------------start------------->8---
(defun fluca1978/align-assignments (beg end)
(interactive "r")
(align-regexp beg end "\\(\\s-*\\)="))
--8<---------------cut here---------------end--------------->8---
When applied to the following region
a = b
ab = t + i
flubble = 17
foo = bar - baz
it aligns it like so:
a = b
ab = t + i
flubble = 17
foo = bar - baz
HTH,
Tassilo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: align-regexp problem when called from lisp code
2013-08-08 11:32 ` Tassilo Horn
@ 2013-08-08 11:57 ` Luca Ferrari
2013-08-09 6:08 ` Luca Ferrari
0 siblings, 1 reply; 8+ messages in thread
From: Luca Ferrari @ 2013-08-08 11:57 UTC (permalink / raw
To: Tassilo Horn; +Cc: help-gnu-emacs
On Thu, Aug 8, 2013 at 1:32 PM, Tassilo Horn <tsdh@gnu.org> wrote:
> --8<---------------cut here---------------start------------->8---
> (defun fluca1978/align-assignments (beg end)
> (interactive "r")
> (align-regexp beg end "\\(\\s-*\\)="))
> --8<---------------cut here---------------end--------------->8---
Thanks, the problem was with the regular expression, not with the
region itself (i.e., I don't need to declare the function as accepting
a region).
Luca
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: align-regexp problem when called from lisp code
2013-08-08 11:57 ` Luca Ferrari
@ 2013-08-09 6:08 ` Luca Ferrari
2013-08-09 8:13 ` Tassilo Horn
0 siblings, 1 reply; 8+ messages in thread
From: Luca Ferrari @ 2013-08-09 6:08 UTC (permalink / raw
To: Tassilo Horn; +Cc: help-gnu-emacs
On Thu, Aug 8, 2013 at 1:57 PM, Luca Ferrari <fluca1978@infinito.it> wrote:
> On Thu, Aug 8, 2013 at 1:32 PM, Tassilo Horn <tsdh@gnu.org> wrote:
>
>> --8<---------------cut here---------------start------------->8---
>> (defun fluca1978/align-assignments (beg end)
>> (interactive "r")
>> (align-regexp beg end "\\(\\s-*\\)="))
>> --8<---------------cut here---------------end--------------->8---
>
Uhm...just for curiosity, what kind of regexp should I use if I want
also to align all comment starting (/*) in every row?
Thanks,
Luca
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: align-regexp problem when called from lisp code
2013-08-09 6:08 ` Luca Ferrari
@ 2013-08-09 8:13 ` Tassilo Horn
2013-08-09 8:45 ` Luca Ferrari
0 siblings, 1 reply; 8+ messages in thread
From: Tassilo Horn @ 2013-08-09 8:13 UTC (permalink / raw
To: Luca Ferrari; +Cc: help-gnu-emacs
Luca Ferrari <fluca1978@infinito.it> writes:
>>> --8<---------------cut here---------------start------------->8---
>>> (defun fluca1978/align-assignments (beg end)
>>> (interactive "r")
>>> (align-regexp beg end "\\(\\s-*\\)="))
>>> --8<---------------cut here---------------end--------------->8---
>
> Uhm...just for curiosity, what kind of regexp should I use if I want
> also to align all comment starting (/*) in every row?
You mean C-style multi-line comments? This
--8<---------------cut here---------------start------------->8---
(defun fluca1978/align-comment (beg end)
(interactive "r")
(align-regexp beg end "\\(\\s-*\\)\\*" 1 0))
--8<---------------cut here---------------end--------------->8---
aligns that
/**
* Here starts a comment
* and here it goes again
* and again
*/
to
/**
* Here starts a comment
* and here it goes again
* and again
*/
Is that what you mean?
Bye,
Tassilo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: align-regexp problem when called from lisp code
2013-08-09 8:13 ` Tassilo Horn
@ 2013-08-09 8:45 ` Luca Ferrari
2013-08-09 9:40 ` Tassilo Horn
0 siblings, 1 reply; 8+ messages in thread
From: Luca Ferrari @ 2013-08-09 8:45 UTC (permalink / raw
To: Tassilo Horn; +Cc: help-gnu-emacs
On Fri, Aug 9, 2013 at 10:13 AM, Tassilo Horn <tsdh@gnu.org> wrote:
> Luca Ferrari <fluca1978@infinito.it> writes:
>
>>>> --8<---------------cut here---------------start------------->8---
>>>> (defun fluca1978/align-assignments (beg end)
>>>> (interactive "r")
>>>> (align-regexp beg end "\\(\\s-*\\)="))
>>>> --8<---------------cut here---------------end--------------->8---
>>
>> Uhm...just for curiosity, what kind of regexp should I use if I want
>> also to align all comment starting (/*) in every row?
>
> You mean C-style multi-line comments? This
>
> --8<---------------cut here---------------start------------->8---
> (defun fluca1978/align-comment (beg end)
> (interactive "r")
> (align-regexp beg end "\\(\\s-*\\)\\*" 1 0))
> --8<---------------cut here---------------end--------------->8---
>
Uhm...no, I was wondering to obtaining some that aligns the
assignments and potential one line comments, so something that from
this:
a = 10; /* 10 is the inital value */
veryLongVariableName = ( a + 2 ); /* should start two more from a */
into this:
a = 10; /* 10 is the inital value */
veryLongVariableName = ( a + 2 ); /* should start two more from a */
So I was thinking about aligning the assignments first and then the
comments (that could have been already aligned by moving the = signs).
Suggestions?
Thanks,
Luca
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: align-regexp problem when called from lisp code
2013-08-09 8:45 ` Luca Ferrari
@ 2013-08-09 9:40 ` Tassilo Horn
2013-08-09 10:03 ` Luca Ferrari
0 siblings, 1 reply; 8+ messages in thread
From: Tassilo Horn @ 2013-08-09 9:40 UTC (permalink / raw
To: Luca Ferrari; +Cc: help-gnu-emacs
Luca Ferrari <fluca1978@infinito.it> writes:
Hi Luca,
> Uhm...no, I was wondering to obtaining some that aligns the
> assignments and potential one line comments, so something that from
> this:
>
> a = 10; /* 10 is the inital value */
> veryLongVariableName = ( a + 2 ); /* should start two more from a */
Ah, ok, then you need to use the REPEAT argument to repeat the alignment
at = and /* throughout the line.
--8<---------------cut here---------------start------------->8---
(defun fluca1978/align-assignments (beg end)
(interactive "r")
(align-regexp beg end "\\(\\s-*\\)\\(?:=\\|/\\*\\)" 1 nil t))
--8<---------------cut here---------------end--------------->8---
This aligns
a = 10; /* 10 is the inital value */
veryLongVariableName = ( a + 2 ); /* should start two more from a */
to
a = 10; /* 10 is the inital value */
veryLongVariableName = ( a + 2 ); /* should start two more from a */
Bye,
Tassilo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: align-regexp problem when called from lisp code
2013-08-09 9:40 ` Tassilo Horn
@ 2013-08-09 10:03 ` Luca Ferrari
0 siblings, 0 replies; 8+ messages in thread
From: Luca Ferrari @ 2013-08-09 10:03 UTC (permalink / raw
To: Tassilo Horn; +Cc: help-gnu-emacs
On Fri, Aug 9, 2013 at 11:40 AM, Tassilo Horn <tsdh@gnu.org> wrote:
> Luca Ferrari <fluca1978@infinito.it> writes:
>
> Hi Luca,
>
>> Uhm...no, I was wondering to obtaining some that aligns the
>> assignments and potential one line comments, so something that from
>> this:
>>
>> a = 10; /* 10 is the inital value */
>> veryLongVariableName = ( a + 2 ); /* should start two more from a */
>
> Ah, ok, then you need to use the REPEAT argument to repeat the alignment
> at = and /* throughout the line.
>
> --8<---------------cut here---------------start------------->8---
> (defun fluca1978/align-assignments (beg end)
> (interactive "r")
> (align-regexp beg end "\\(\\s-*\\)\\(?:=\\|/\\*\\)" 1 nil t))
> --8<---------------cut here---------------end--------------->8---
Great!
Thank you very much!
Luca
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-08-09 10:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-08 10:34 align-regexp problem when called from lisp code Luca Ferrari
2013-08-08 11:32 ` Tassilo Horn
2013-08-08 11:57 ` Luca Ferrari
2013-08-09 6:08 ` Luca Ferrari
2013-08-09 8:13 ` Tassilo Horn
2013-08-09 8:45 ` Luca Ferrari
2013-08-09 9:40 ` Tassilo Horn
2013-08-09 10:03 ` Luca Ferrari
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.