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: Andreas Politz
Subject: Re: Writing a function for a indented copy of a region
Date: Thu, 18 Dec 2008 01:27:55 +0100
User-agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018)

Decebal wrote:
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?

You are using a undefined function ?

-ap


reply via email to

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