* `align-regexp' fails in Lisp code
@ 2013-07-10 0:11 Raffaele Ricciardi
2013-07-10 2:58 ` Leo Liu
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Raffaele Ricciardi @ 2013-07-10 0:11 UTC (permalink / raw)
To: help-gnu-emacs
Hello everyone,
I'm trying to run `align-regexp' from Lisp code, but it fails with
the error "align-region: Marker does not point anywhere".
Here is the specification of `align-regexp':
---
(align-regexp BEG END REGEXP &optional GROUP SPACING REPEAT)
Align the current region using an ad-hoc rule read from the
minibuffer. BEG and END mark the limits of the region.
---
Here is my Lisp code:
(align-regexp (point-min) (point-max) " hides ")
Marking the whole buffer and calling `align-regexp' interactively does
work, though.
Tried with "emacs -Q". I'm using GNU Emacs 24.3.1.
Thank you for your attention.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: `align-regexp' fails in Lisp code
2013-07-10 0:11 `align-regexp' fails in Lisp code Raffaele Ricciardi
@ 2013-07-10 2:58 ` Leo Liu
2013-07-10 3:14 ` Michael Heerdegen
[not found] ` <mailman.723.1373426169.12400.help-gnu-emacs@gnu.org>
2013-07-10 3:14 ` Le Wang
2013-07-12 13:18 ` Jambunathan K
2 siblings, 2 replies; 11+ messages in thread
From: Leo Liu @ 2013-07-10 2:58 UTC (permalink / raw)
To: Raffaele Ricciardi; +Cc: help-gnu-emacs
On 2013-07-10 08:11 +0800, Raffaele Ricciardi wrote:
> Marking the whole buffer and calling `align-regexp' interactively does
> work
Because the function works on a region as stated in its doc-string.
Leo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: `align-regexp' fails in Lisp code
2013-07-10 0:11 `align-regexp' fails in Lisp code Raffaele Ricciardi
2013-07-10 2:58 ` Leo Liu
@ 2013-07-10 3:14 ` Le Wang
2013-07-12 13:18 ` Jambunathan K
2 siblings, 0 replies; 11+ messages in thread
From: Le Wang @ 2013-07-10 3:14 UTC (permalink / raw)
To: Raffaele Ricciardi; +Cc: GNU Emacs List
I can find at least 4 variations of this question on stackoverflow.
This answer describes what's happening well:
http://stackoverflow.com/a/12975000/903943
Essentially, the parameters received by the function are pre-processed
by interactive forms, so you're not calling it correctly.
See also difference between function and command, interactive forms
sections of the docs.
On Wed, Jul 10, 2013 at 8:11 AM, Raffaele Ricciardi <rfflrccrd@gmail.com> wrote:
> Hello everyone,
>
> I'm trying to run `align-regexp' from Lisp code, but it fails with
> the error "align-region: Marker does not point anywhere".
>
> Here is the specification of `align-regexp':
>
> ---
>
> (align-regexp BEG END REGEXP &optional GROUP SPACING REPEAT)
>
> Align the current region using an ad-hoc rule read from the
> minibuffer. BEG and END mark the limits of the region.
>
> ---
>
> Here is my Lisp code:
>
> (align-regexp (point-min) (point-max) " hides ")
>
> Marking the whole buffer and calling `align-regexp' interactively does
> work, though.
>
> Tried with "emacs -Q". I'm using GNU Emacs 24.3.1.
>
> Thank you for your attention.
>
>
>
>
--
Le
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: `align-regexp' fails in Lisp code
2013-07-10 2:58 ` Leo Liu
@ 2013-07-10 3:14 ` Michael Heerdegen
2013-07-11 11:55 ` andrea crotti
[not found] ` <mailman.723.1373426169.12400.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 11+ messages in thread
From: Michael Heerdegen @ 2013-07-10 3:14 UTC (permalink / raw)
To: help-gnu-emacs
Leo Liu <sdl.web@gmail.com> writes:
> On 2013-07-10 08:11 +0800, Raffaele Ricciardi wrote:
> > Marking the whole buffer and calling `align-regexp' interactively does
> > work
>
> Because the function works on a region as stated in its doc-string.
If that's right (it seems so), then the doc-string should clearly say
that this command is not for non-interactive use, or how it can be
called from Lisp.
Michael.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: `align-regexp' fails in Lisp code
2013-07-10 3:14 ` Michael Heerdegen
@ 2013-07-11 11:55 ` andrea crotti
2013-07-11 12:02 ` Nicolas Richard
0 siblings, 1 reply; 11+ messages in thread
From: andrea crotti @ 2013-07-11 11:55 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs@gnu.org
"align-regexp is an interactive autoloaded Lisp function in `align.el'."
it says it's interactive in the doc..
2013/7/10 Michael Heerdegen <michael_heerdegen@web.de>
> Leo Liu <sdl.web@gmail.com> writes:
>
> > On 2013-07-10 08:11 +0800, Raffaele Ricciardi wrote:
> > > Marking the whole buffer and calling `align-regexp' interactively does
> > > work
> >
> > Because the function works on a region as stated in its doc-string.
>
> If that's right (it seems so), then the doc-string should clearly say
> that this command is not for non-interactive use, or how it can be
> called from Lisp.
>
>
> Michael.
>
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: `align-regexp' fails in Lisp code
2013-07-11 11:55 ` andrea crotti
@ 2013-07-11 12:02 ` Nicolas Richard
0 siblings, 0 replies; 11+ messages in thread
From: Nicolas Richard @ 2013-07-11 12:02 UTC (permalink / raw)
To: andrea crotti; +Cc: Michael Heerdegen, help-gnu-emacs@gnu.org
andrea crotti <andrea.crotti.0@gmail.com> writes:
> "align-regexp is an interactive autoloaded Lisp function in `align.el'."
>
> it says it's interactive in the doc..
And so is goto-char :
"goto-char is an interactive built-in function in `editfns.c'."
This doesn't mean that goto-char shouldn't be used from lisp.
--
Nico.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: `align-regexp' fails in Lisp code
[not found] ` <mailman.723.1373426169.12400.help-gnu-emacs@gnu.org>
@ 2013-07-11 23:29 ` Raffaele Ricciardi
2013-07-12 0:26 ` Michael Heerdegen
[not found] ` <mailman.883.1373588795.12400.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 11+ messages in thread
From: Raffaele Ricciardi @ 2013-07-11 23:29 UTC (permalink / raw)
To: help-gnu-emacs
On 10/07/13 05:14, Michael Heerdegen wrote:
> Leo Liu <sdl.web@gmail.com> writes:
>
>> On 2013-07-10 08:11 +0800, Raffaele Ricciardi wrote:
>>> Marking the whole buffer and calling `align-regexp' interactively does
>>> work
>>
>> Because the function works on a region as stated in its doc-string.
>
> If that's right (it seems so), then the doc-string should clearly say
> that this command is not for non-interactive use, or how it can be
> called from Lisp.
Two positions make a region, hence the call:
(align-regexp (point-min) (point-max) " hides ")
is correct.
The problem is that - I had to look into Lisp code to understand - the
regexp that you enter in the mini-buffer is not the regexp that
`align-regexp' receives, because of a conversion applied by the
`interactive' form inside the command. Hence I agree with you - but for
a different reason - that the documentation should say how the command
could be called from Lisp.
Here is a wrapper to call `align-regexp' from Lisp with no prefix arg :
(defun align-regexp-function (^start ^end ^regexp)
"Like `align-regexp' when no prefix arg was specified,
but callable from Lisp."
;; Convert arguments like the `interactive' form
;; in `align-regexp' does when no prefix arg was specified.
(align-regexp ^start
^end
(concat "\\(\\s-*\\)" ^regexp)
1
align-default-spacing
nil))
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: `align-regexp' fails in Lisp code
2013-07-11 23:29 ` Raffaele Ricciardi
@ 2013-07-12 0:26 ` Michael Heerdegen
[not found] ` <mailman.883.1373588795.12400.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 11+ messages in thread
From: Michael Heerdegen @ 2013-07-12 0:26 UTC (permalink / raw)
To: help-gnu-emacs
Raffaele Ricciardi <rfflrccrd@gmail.com> writes:
> Two positions make a region, hence the call:
>
> (align-regexp (point-min) (point-max) " hides ")
>
> is correct.
>
> The problem is that - I had to look into Lisp code to understand - the
> regexp that you enter in the mini-buffer is not the regexp that
> align-regexp' receives, because of a conversion applied by the
> interactive' form inside the command. Hence I agree with you - but
> for a different reason - that the documentation should say how the
> command could be called from Lisp.
Interesting. Do you also understand why
(align-regexp (point-min) (point-max) " hides ")
is illegitimate? After having read the doc, I don't understand why this
call must lead to an error.
Regards,
Michael.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: `align-regexp' fails in Lisp code
[not found] ` <mailman.883.1373588795.12400.help-gnu-emacs@gnu.org>
@ 2013-07-12 13:04 ` Raffaele Ricciardi
2013-07-12 23:16 ` Michael Heerdegen
0 siblings, 1 reply; 11+ messages in thread
From: Raffaele Ricciardi @ 2013-07-12 13:04 UTC (permalink / raw)
To: help-gnu-emacs
On 12/07/13 02:26, Michael Heerdegen wrote:
> Interesting. Do you also understand why
>
> (align-regexp (point-min) (point-max) " hides ")
>
> is illegitimate? After having read the doc, I don't understand why this
> call must lead to an error.
Indeed, the doc doesn't touch the issue. If you call `align-regexp'
with the regexp that you would have typed in the mini-buffer, then you
won't be calling `align-regexp' with the regexp that it expects, because
a regexp typed in the mini-buffer would have been converted into
something else.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: `align-regexp' fails in Lisp code
2013-07-10 0:11 `align-regexp' fails in Lisp code Raffaele Ricciardi
2013-07-10 2:58 ` Leo Liu
2013-07-10 3:14 ` Le Wang
@ 2013-07-12 13:18 ` Jambunathan K
2 siblings, 0 replies; 11+ messages in thread
From: Jambunathan K @ 2013-07-12 13:18 UTC (permalink / raw)
To: Raffaele Ricciardi; +Cc: help-gnu-emacs
Run the command as usual
M-x align-regexp RET
Let Emacs tell you what the lisp representation of it is. Do
M-x list-command-history RET
you will find your very recent command there.
Copy, paste that stuff, do some modifications for the region portion and
your are done.
----------------------------------------------------------------
You can also get the lisp representation with
M-x repeat-complex-command RET
M-p
M-p
etc
until you find what you want.
Raffaele Ricciardi <rfflrccrd@gmail.com> writes:
> Hello everyone,
>
> I'm trying to run `align-regexp' from Lisp code, but it fails with
> the error "align-region: Marker does not point anywhere".
>
> Here is the specification of `align-regexp':
>
> ---
>
> (align-regexp BEG END REGEXP &optional GROUP SPACING REPEAT)
>
> Align the current region using an ad-hoc rule read from the
> minibuffer. BEG and END mark the limits of the region.
>
> ---
>
> Here is my Lisp code:
>
> (align-regexp (point-min) (point-max) " hides ")
>
> Marking the whole buffer and calling `align-regexp' interactively does
> work, though.
>
> Tried with "emacs -Q". I'm using GNU Emacs 24.3.1.
>
> Thank you for your attention.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: `align-regexp' fails in Lisp code
2013-07-12 13:04 ` Raffaele Ricciardi
@ 2013-07-12 23:16 ` Michael Heerdegen
0 siblings, 0 replies; 11+ messages in thread
From: Michael Heerdegen @ 2013-07-12 23:16 UTC (permalink / raw)
To: help-gnu-emacs
Raffaele Ricciardi <rfflrccrd@gmail.com> writes:
> > Interesting. Do you also understand why
> >
> > (align-regexp (point-min) (point-max) " hides ")
> >
> > is illegitimate? After having read the doc, I don't understand why this
> > call must lead to an error.
>
> Indeed, the doc doesn't touch the issue. If you call `align-regexp'
> with the regexp that you would have typed in the mini-buffer, then you
> won't be calling `align-regexp' with the regexp that it expects,
> because a regexp typed in the mini-buffer would have been converted
> into something else.
The doc is just incomplete, so I filed a bug report. It's bug 14857
now.
Regards,
Michael.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2013-07-12 23:16 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-10 0:11 `align-regexp' fails in Lisp code Raffaele Ricciardi
2013-07-10 2:58 ` Leo Liu
2013-07-10 3:14 ` Michael Heerdegen
2013-07-11 11:55 ` andrea crotti
2013-07-11 12:02 ` Nicolas Richard
[not found] ` <mailman.723.1373426169.12400.help-gnu-emacs@gnu.org>
2013-07-11 23:29 ` Raffaele Ricciardi
2013-07-12 0:26 ` Michael Heerdegen
[not found] ` <mailman.883.1373588795.12400.help-gnu-emacs@gnu.org>
2013-07-12 13:04 ` Raffaele Ricciardi
2013-07-12 23:16 ` Michael Heerdegen
2013-07-10 3:14 ` Le Wang
2013-07-12 13:18 ` Jambunathan K
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).