help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `align-regexp' fails in Lisp code


From: Raffaele Ricciardi
Subject: Re: `align-regexp' fails in Lisp code
Date: Fri, 12 Jul 2013 01:29:33 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130215 Thunderbird/17.0.3

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))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]