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

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

Re: narrow-to-region for a rectangle


From: C K Kashyap
Subject: Re: narrow-to-region for a rectangle
Date: Wed, 5 Jun 2013 12:04:30 +0530

This is what I've come up with. I'd really appreciate some feedback.

(defun k-quotes (beg end st en)
  (interactive "r*\nsStart Pattern: \nsEnd Pattern: \n")
  (save-excursion
    (save-restriction
      (string-rectangle beg end st)
      (move-end-of-line nil)
      (setq newEnd (point))
      (goto-char beg)
      (replace-regexp "$" en  nil beg newEnd)
      (replace-regexp (concat en "$") "")
      )))

Regards,
Kashyap


On Tue, Jun 4, 2013 at 6:23 PM, C K Kashyap <ckkashyap@gmail.com> wrote:

> The function below takes in a region and surrounds each line with input
> strings -
>
> (defun k-quotes (beg end st en)
>   (interactive "r*\nsStart Pattern: \nsEnd Pattern: \n")
>   (save-excursion
>     (save-restriction
>       (narrow-to-region beg end)
>       (goto-char beg)
>       (replace-regexp "\\(.*\\)" (concat st "\\1" en))
>        )))
>
> I'd like this function to be able to restrict to a rectangle instead of a
> region. While on the first line it restricts "^" to match whereever I
> started the mark from - on the rest of the lines, its the beginning of the
> line.
>
> Regards,
> Kashyap
>
>
> On Tue, Jun 4, 2013 at 6:10 PM, Jambunathan K <kjambunathan@gmail.com>wrote:
>
>> C K Kashyap <ckkashyap@gmail.com> writes:
>>
>> > Hi,
>> > Is there a function that restricts the modifiable area to the rectangle
>> > rather than  the region?
>>
>> If such a thing is available, what will you do with it?  Give an
>> example.
>>
>> > Regards,
>> > Kashyap
>>
>
>


reply via email to

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