* narrow-to-region for a rectangle
@ 2013-06-04 12:23 C K Kashyap
2013-06-04 12:40 ` Jambunathan K
0 siblings, 1 reply; 6+ messages in thread
From: C K Kashyap @ 2013-06-04 12:23 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
Is there a function that restricts the modifiable area to the rectangle
rather than the region?
Regards,
Kashyap
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: narrow-to-region for a rectangle
2013-06-04 12:23 narrow-to-region for a rectangle C K Kashyap
@ 2013-06-04 12:40 ` Jambunathan K
2013-06-04 12:53 ` C K Kashyap
0 siblings, 1 reply; 6+ messages in thread
From: Jambunathan K @ 2013-06-04 12:40 UTC (permalink / raw)
To: C K Kashyap; +Cc: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: narrow-to-region for a rectangle
2013-06-04 12:40 ` Jambunathan K
@ 2013-06-04 12:53 ` C K Kashyap
2013-06-05 6:34 ` C K Kashyap
0 siblings, 1 reply; 6+ messages in thread
From: C K Kashyap @ 2013-06-04 12:53 UTC (permalink / raw)
To: Jambunathan K; +Cc: help-gnu-emacs
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
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: narrow-to-region for a rectangle
2013-06-04 12:53 ` C K Kashyap
@ 2013-06-05 6:34 ` C K Kashyap
2013-06-05 6:50 ` Jambunathan K
0 siblings, 1 reply; 6+ messages in thread
From: C K Kashyap @ 2013-06-05 6:34 UTC (permalink / raw)
To: Jambunathan K; +Cc: help-gnu-emacs
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
>>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: narrow-to-region for a rectangle
2013-06-05 6:34 ` C K Kashyap
@ 2013-06-05 6:50 ` Jambunathan K
2013-06-06 6:06 ` C K Kashyap
0 siblings, 1 reply; 6+ messages in thread
From: Jambunathan K @ 2013-06-05 6:50 UTC (permalink / raw)
To: C K Kashyap; +Cc: help-gnu-emacs
C K Kashyap <ckkashyap@gmail.com> writes:
> This is what I've come up with. I'd really appreciate some feedback.
Others have provided feedback and they are all good. If it gets the job
done, you should bother (yourself and others) no more.
If one is interested in working with rectangles - edit text (with
filling, justification, what not), narrow it (and have regexp matchers
^, $ do the expected) then one can look at table.el and extract portions
of it to the Emacs "core".
Remember, rectangle is but a table cell (possibly with no "geometric
rectangle" surrounding it.)
,---- From commentary section of table.el
|
| ;; The most difficult part of dealing with table editing in Emacs
| ;; probably is how to realize localized rectangular editing effect.
| ;; Emacs has no rectangular narrowing mechanism. Existing rect package
| ;; provides basically kill, delete and yank operations of a rectangle,
| ;; which internally is a mere list of strings.
|
| ;; A simple approach for realizing the localized virtual rectangular
| ;; operation is combining rect package capability with a temporary
| ;; buffer. Insertion and deletion of a character to a table cell can be
| ;; trapped by a function that copies the cell rectangle to a temporary
| ;; buffer then apply the insertion/deletion to the temporary contents.
| ;; Then it formats the contents by filling the paragraphs in order to
| ;; fit it into the original rectangular area and finally copy it back to
| ;; the original buffer.
|
| ;; This simplistic approach has to bear with significant performance
| ;; hit. As cell grows larger the copying rectangle back and forth
| ;; between the original buffer and the temporary buffer becomes
| ;; expensive and unbearably slow. It was completely impractical and an
| ;; obvious failure.
|
| ;; An idea has been borrowed from the original Emacs design to overcome
| ;; this shortcoming. When the terminal screen update was slow and
| ;; expensive Emacs employed a clever algorithm to reduce actual screen
| ;; update by removing redundant redrawing operations. Also the actual
| ;; redrawing was done only when there was enough idling time. This
| ;; technique significantly improved the previously mentioned undesirable
| ;; situation. Now the original buffer's rectangle is copied into a
| ;; cache buffer only once. Any cell editing operation is done only to
| ;; the cache contents. When there is enough idling time the original
| ;; buffer's rectangle is updated with the current cache contents. This
| ;; delayed operation is implemented by using Emacs's timer function. To
| ;; reduce the visual awkwardness introduced by the delayed effect the
| ;; cursor location is updated in real-time as a user types while the
| ;; cell contents remains the same until the next idling time. A key to
| ;; the success of this approach is how to maintain cache coherency. As
| ;; a user moves point in and out of a cell the table buffer contents and
| ;; the cache buffer contents must be synchronized without a mistake. By
| ;; observing user action carefully this is possible however not easy.
| ;; Once this mechanism is firmly implemented the rest of table features
| ;; grew in relatively painless progression.
|
| ;; Those users who are familiar with Emacs internals appreciate this
| ;; table package more. Because it demonstrates how extensible Emacs is
| ;; by showing something that appears like a magic. It lets you
| ;; re-discover the potential of Emacs.
|
`----
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: narrow-to-region for a rectangle
2013-06-05 6:50 ` Jambunathan K
@ 2013-06-06 6:06 ` C K Kashyap
0 siblings, 0 replies; 6+ messages in thread
From: C K Kashyap @ 2013-06-06 6:06 UTC (permalink / raw)
To: Jambunathan K; +Cc: help-gnu-emacs
Thanks for the pointer Jambunathan.
Yeah, I guess this horse has been more than beaten to death :)
Regards,
Kashyap
On Wed, Jun 5, 2013 at 12:20 PM, Jambunathan K <kjambunathan@gmail.com>wrote:
> C K Kashyap <ckkashyap@gmail.com> writes:
>
> > This is what I've come up with. I'd really appreciate some feedback.
>
> Others have provided feedback and they are all good. If it gets the job
> done, you should bother (yourself and others) no more.
>
> If one is interested in working with rectangles - edit text (with
> filling, justification, what not), narrow it (and have regexp matchers
> ^, $ do the expected) then one can look at table.el and extract portions
> of it to the Emacs "core".
>
> Remember, rectangle is but a table cell (possibly with no "geometric
> rectangle" surrounding it.)
>
> ,---- From commentary section of table.el
> |
> | ;; The most difficult part of dealing with table editing in Emacs
> | ;; probably is how to realize localized rectangular editing effect.
> | ;; Emacs has no rectangular narrowing mechanism. Existing rect package
> | ;; provides basically kill, delete and yank operations of a rectangle,
> | ;; which internally is a mere list of strings.
> |
> | ;; A simple approach for realizing the localized virtual rectangular
> | ;; operation is combining rect package capability with a temporary
> | ;; buffer. Insertion and deletion of a character to a table cell can be
> | ;; trapped by a function that copies the cell rectangle to a temporary
> | ;; buffer then apply the insertion/deletion to the temporary contents.
> | ;; Then it formats the contents by filling the paragraphs in order to
> | ;; fit it into the original rectangular area and finally copy it back to
> | ;; the original buffer.
> |
> | ;; This simplistic approach has to bear with significant performance
> | ;; hit. As cell grows larger the copying rectangle back and forth
> | ;; between the original buffer and the temporary buffer becomes
> | ;; expensive and unbearably slow. It was completely impractical and an
> | ;; obvious failure.
> |
> | ;; An idea has been borrowed from the original Emacs design to overcome
> | ;; this shortcoming. When the terminal screen update was slow and
> | ;; expensive Emacs employed a clever algorithm to reduce actual screen
> | ;; update by removing redundant redrawing operations. Also the actual
> | ;; redrawing was done only when there was enough idling time. This
> | ;; technique significantly improved the previously mentioned undesirable
> | ;; situation. Now the original buffer's rectangle is copied into a
> | ;; cache buffer only once. Any cell editing operation is done only to
> | ;; the cache contents. When there is enough idling time the original
> | ;; buffer's rectangle is updated with the current cache contents. This
> | ;; delayed operation is implemented by using Emacs's timer function. To
> | ;; reduce the visual awkwardness introduced by the delayed effect the
> | ;; cursor location is updated in real-time as a user types while the
> | ;; cell contents remains the same until the next idling time. A key to
> | ;; the success of this approach is how to maintain cache coherency. As
> | ;; a user moves point in and out of a cell the table buffer contents and
> | ;; the cache buffer contents must be synchronized without a mistake. By
> | ;; observing user action carefully this is possible however not easy.
> | ;; Once this mechanism is firmly implemented the rest of table features
> | ;; grew in relatively painless progression.
> |
> | ;; Those users who are familiar with Emacs internals appreciate this
> | ;; table package more. Because it demonstrates how extensible Emacs is
> | ;; by showing something that appears like a magic. It lets you
> | ;; re-discover the potential of Emacs.
> |
> `----
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-06-06 6:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-04 12:23 narrow-to-region for a rectangle C K Kashyap
2013-06-04 12:40 ` Jambunathan K
2013-06-04 12:53 ` C K Kashyap
2013-06-05 6:34 ` C K Kashyap
2013-06-05 6:50 ` Jambunathan K
2013-06-06 6:06 ` C K Kashyap
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).