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

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

Re: align-regexp problem when called from lisp code


From: Tassilo Horn
Subject: Re: align-regexp problem when called from lisp code
Date: Thu, 08 Aug 2013 13:32:32 +0200
User-agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux)

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



reply via email to

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