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

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

Re: Writing a function for a indented copy of a region


From: Decebal
Subject: Re: Writing a function for a indented copy of a region
Date: Wed, 17 Dec 2008 15:37:37 -0800 (PST)
User-agent: G2/1.0

On 17 dec, 20:47, Andreas Politz <poli...@fh-trier.de> wrote:
> Why not work with a string, instead of messing with your buffers undo history.
>
> (defun kill-save-indent-region (indent start end)
>    (interactive "p\nr")
>    (kill-new (replace-regexp-in-string
>              "^"                      ;or "^\\s-*"
>              (format (format "%%%ds" (case indent
>                                        (0 1)
>                                        (1 4)
>                                        (t indent)))
>                      "")
>              (buffer-substring start end)))
>    (deactivate-mark))

Looking at your code I should replace:
        (indent-rigidly (region-beginning) (region-end) indent)
        (if do-kill
            (kill-region (region-beginning) (region-end))
          (copy-region-as-kill (region-beginning) (region-end))
          (undo)
          )
with:
        (kill-new (replace-regexp-in-string
                   "^"
                   (format (format "%%%ds" indent) "")
                   (filter-buffer-substring (region-beginning) (region-
end) do-kill)
                   )
                  )

but then I get that filter-buffer-substring is void. What am I doing
wrong?


reply via email to

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