GNU bug report logs -
#17401
24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window
Previous Next
To reply to this bug, email your comments to 17401 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#17401
; Package
emacs
.
(Sun, 04 May 2014 10:40:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Phil Sainty <psainty <at> orcon.net.nz>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sun, 04 May 2014 10:40:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
I encountered a blog post by Zane Ashby detailing this idea, and it
was one of those "why did I never think of that?" moments, because
I was doing this manually on a regular basis.
http://demonastery.org/2013/04/emacs-narrow-to-region-indirect/
That post provides a function which creates a indirect clone of
the current buffer, and narrows to the marked region in that, so
that you have both the original un-narrowed buffer and the narrowed
indirect clone available simultaneously.
This is incredibly useful, and it seems like an obvious contender
for standard functionality in Emacs.
I'm attaching a patch which uses that approach to implement the
following functions and bindings:
C-x 4 n n: narrow-to-region-indirect-other-window
C-x 4 n p: narrow-to-page-indirect-other-window
C-x 4 n d: narrow-to-defun-indirect-other-window
It's still essentially Zane's code, so I've confirmed that he's
happy for me to send this, and am CCing this to him.
-Phil
In GNU Emacs 24.4.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.10)
of 2014-05-03 on xerxes
Windowing system distributor `The X.Org Foundation', version 11.0.11300000
System Description: Ubuntu 12.04.4 LTS
Configured using:
`configure --prefix=/usr/local/src/emacs/usr/local --without-sound'
Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK DBUS GSETTINGS NOTIFY GNUTLS
LIBXML2 FREETYPE XFT ZLIB
Important settings:
value of $LANG: en_NZ.UTF-8
locale-coding-system: utf-8-unix
Major mode: Lisp Interaction
Minor modes in effect:
tooltip-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
Recent input:
<help-echo> M-x r e p o r t - e m <tab> <return>
Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
user-error: End of history; no default available
Load-path shadows:
None found.
Features:
(shadow sort gnus-util mail-extr emacsbug message dired format-spec
rfc822 mml easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util help-fns mail-prsvr mail-utils time-date tooltip
electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode prog-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple
abbrev minibuffer nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
dbusbind gfilenotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)
Memory information:
((conses 16 74917 6338)
(symbols 48 17834 0)
(miscs 40 35 138)
(strings 32 10321 4869)
(string-bytes 1 288458)
(vectors 16 9191)
(vector-slots 8 374331 12806)
(floats 8 63 98)
(intervals 56 170 0)
(buffers 960 11)
(heap 1024 19710 771))
[narrow-indirect-other-buffer.patch (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#17401
; Package
emacs
.
(Sun, 04 May 2014 13:45:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 17401 <at> debbugs.gnu.org (full text, mbox):
+1
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#17401
; Package
emacs
.
(Thu, 08 May 2014 00:07:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 17401 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Here is my current version (which I think perhaps Phil can make something
better of):
(defun narrow-to-region-indirect (start end here name-suffix)
"Restrict editing in this buffer to the current region, indirectly."
(interactive (list (region-beginning) (region-end) (region-beginning) ""))
(deactivate-mark)
(let ((posdiff (- here start))
(name (buffer-name))
(line name-suffix))
(save-excursion
(goto-char start)
(while (and (not (eobp)) (string= line ""))
(setq line (buffer-substring-no-properties (point-at-bol)
(point-at-eol)))
(setq line (replace-regexp-in-string "^\s+\\|\s+$" "" line))
(forward-line)))
(let* ((bn (concat name " <" line ">"))
(buf (clone-indirect-buffer bn nil)))
(with-current-buffer buf
(narrow-to-region start end)
(goto-char start)
(forward-char posdiff))
(switch-to-buffer buf))))
(defun narrow-to-defun-indirect ()
"Restrict editing in this buffer to the current function, indirectly."
(interactive)
(require 'which-func)
(let ((here (point))
(suffix (which-function)))
(mark-defun)
(narrow-to-region-indirect (region-beginning) (region-end) here
suffix)))
On Sun, May 4, 2014 at 12:38 PM, Phil Sainty <psainty <at> orcon.net.nz> wrote:
> I encountered a blog post by Zane Ashby detailing this idea, and it
> was one of those "why did I never think of that?" moments, because
> I was doing this manually on a regular basis.
>
> http://demonastery.org/2013/04/emacs-narrow-to-region-indirect/
>
> That post provides a function which creates a indirect clone of
> the current buffer, and narrows to the marked region in that, so
> that you have both the original un-narrowed buffer and the narrowed
> indirect clone available simultaneously.
>
> This is incredibly useful, and it seems like an obvious contender
> for standard functionality in Emacs.
>
> I'm attaching a patch which uses that approach to implement the
> following functions and bindings:
>
> C-x 4 n n: narrow-to-region-indirect-other-window
> C-x 4 n p: narrow-to-page-indirect-other-window
> C-x 4 n d: narrow-to-defun-indirect-other-window
>
> It's still essentially Zane's code, so I've confirmed that he's
> happy for me to send this, and am CCing this to him.
>
>
> -Phil
>
>
>
>
>
> In GNU Emacs 24.4.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.10)
> of 2014-05-03 on xerxes
> Windowing system distributor `The X.Org Foundation', version 11.0.11300000
> System Description: Ubuntu 12.04.4 LTS
>
> Configured using:
> `configure --prefix=/usr/local/src/emacs/usr/local --without-sound'
>
> Configured features:
> XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK DBUS GSETTINGS NOTIFY GNUTLS
> LIBXML2 FREETYPE XFT ZLIB
>
> Important settings:
> value of $LANG: en_NZ.UTF-8
> locale-coding-system: utf-8-unix
>
> Major mode: Lisp Interaction
>
> Minor modes in effect:
> tooltip-mode: t
> electric-indent-mode: t
> mouse-wheel-mode: t
> tool-bar-mode: t
> menu-bar-mode: t
> file-name-shadow-mode: t
> global-font-lock-mode: t
> font-lock-mode: t
> blink-cursor-mode: t
> auto-composition-mode: t
> auto-encryption-mode: t
> auto-compression-mode: t
> line-number-mode: t
> transient-mark-mode: t
>
> Recent input:
> <help-echo> M-x r e p o r t - e m <tab> <return>
>
> Recent messages:
> For information about GNU Emacs and the GNU system, type C-h C-a.
> user-error: End of history; no default available
>
> Load-path shadows:
> None found.
>
> Features:
> (shadow sort gnus-util mail-extr emacsbug message dired format-spec
> rfc822 mml easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse
> rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
> ietf-drums mm-util help-fns mail-prsvr mail-utils time-date tooltip
> electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
> tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
> lisp-mode prog-mode register page menu-bar rfn-eshadow timer select
> scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham
> georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
> korean japanese hebrew greek romanian slovak czech european ethiopic
> indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple
> abbrev minibuffer nadvice loaddefs button faces cus-face macroexp files
> text-properties overlay sha1 md5 base64 format env code-pages mule
> custom widget hashtable-print-readable backquote make-network-process
> dbusbind gfilenotify dynamic-setting system-font-setting
> font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)
>
> Memory information:
> ((conses 16 74917 6338)
> (symbols 48 17834 0)
> (miscs 40 35 138)
> (strings 32 10321 4869)
> (string-bytes 1 288458)
> (vectors 16 9191)
> (vector-slots 8 374331 12806)
> (floats 8 63 98)
> (intervals 56 170 0)
> (buffers 960 11)
> (heap 1024 19710 771))
>
>
>
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#17401
; Package
emacs
.
(Sat, 10 May 2014 13:08:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 17401 <at> debbugs.gnu.org (full text, mbox):
On 8/05/2014 12:05, Lennart Borgman wrote:
> Here is my current version (which I think perhaps Phil can
> make something better of)
I was initially against the idea of naming the indirect buffer
according to the narrowed region, for the simple reason that the
name stops making sense as soon as you widen the buffer.
However, I expect that people are far less likely to widen these
buffers (as opposed to simply killing them); and this naming
approach would certainly be useful in the buffer list, so I think
it's a good idea after all.
I've also noticed there are some org-mode specific narrowing
commands as well, which should probably be supported. I did
consider whether we could support all existing narrowing commands
automagically with some trickery, but I concluded that the only
approach I could think of was too convoluted and brittle for its
own good, so I think simply adding a new function alongside each
existing one is still the most practical way to go.
Do we want both a `narrow-to-*-indirect' and an `...-other-window'
variant for each case? I think the latter works very nicely with
the C-x 4 n prefix (as per the initial patch), but I can see the
utility in providing both functions.
-Phil
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#17401
; Package
emacs
.
(Sat, 10 May 2014 20:59:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 17401 <at> debbugs.gnu.org (full text, mbox):
On Sat, May 10, 2014 at 6:06 AM, Phil Sainty <psainty <at> orcon.net.nz> wrote:
> I've also noticed there are some org-mode specific narrowing
> commands as well, which should probably be supported. I did
> consider whether we could support all existing narrowing commands
> automagically with some trickery, but I concluded that the only
> approach I could think of was too convoluted and brittle for its
> own good, so I think simply adding a new function alongside each
> existing one is still the most practical way to go.
>
> Do we want both a `narrow-to-*-indirect' and an `...-other-window'
> variant for each case? I think the latter works very nicely with
> the C-x 4 n prefix (as per the initial patch), but I can see the
> utility in providing both functions.
What about doing something like `append-next-kill', for example a
new `next-narrow-indirect' command bound to `C-x n i'?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#17401
; Package
emacs
.
(Sun, 11 May 2014 04:13:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 17401 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
> I was initially against the idea of naming the indirect buffer
> according to the narrowed region, for the simple reason that the
> name stops making sense as soon as you widen the buffer.
>
> However, I expect that people are far less likely to widen these
> buffers (as opposed to simply killing them); and this naming
> approach would certainly be useful in the buffer list, so I think
> it's a good idea after all.
>
> I've also noticed there are some org-mode specific narrowing
> commands as well, which should probably be supported. I did
> consider whether we could support all existing narrowing commands
> automagically with some trickery, but I concluded that the only
> approach I could think of was too convoluted and brittle for its
> own good, so I think simply adding a new function alongside each
> existing one is still the most practical way to go.
>
> Do we want both a `narrow-to-*-indirect' and an `...-other-window'
> variant for each case? I think the latter works very nicely with
> the C-x 4 n prefix (as per the initial patch), but I can see the
> utility in providing both functions.
I agree about killing vs widening indirect buffers. And I
don't find a need for same-window versions of the commands,
for my own use.
FWIW, attached is what I've been using lately.
The default buffer naming is similar to what Lennart suggested,
but (for the non-defun command) the region text (with whitespace
collapsed) is used, not the first line. And the buffer-name
length is limited. And the text following the original name is
separated by ` | ' instead of being enclosed in <...>.
Two options control naming: one limits the length, the other
is a name prefix (e.g., to easily distinguish indirect buffers).
A prefix arg prompts you for the new buffer name.
For defun narrowing, a negative prefix arg prompts you for the
text that follows ` | ' (in place of the defun object name).
To me, being able to provide names different from the default
is important.
--
(FWIW, I also use library `wide-n.el', which lets you widen
to any number of narrowings of the same buffer - e.g., cycle.
http://www.emacswiki.org/emacs-de/MultipleNarrowings)
[narrow-other.el (application/octet-stream, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#17401
; Package
emacs
.
(Fri, 18 Sep 2020 13:58:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 17401 <at> debbugs.gnu.org (full text, mbox):
Phil Sainty <psainty <at> orcon.net.nz> writes:
> That post provides a function which creates a indirect clone of
> the current buffer, and narrows to the marked region in that, so
> that you have both the original un-narrowed buffer and the narrowed
> indirect clone available simultaneously.
>
> This is incredibly useful, and it seems like an obvious contender
> for standard functionality in Emacs.
>
> I'm attaching a patch which uses that approach to implement the
> following functions and bindings:
>
> C-x 4 n n: narrow-to-region-indirect-other-window
> C-x 4 n p: narrow-to-page-indirect-other-window
> C-x 4 n d: narrow-to-defun-indirect-other-window
Sounds like a good idea to me, and seems to be a logical extension.
Anybody got an opinion?
However:
> It's still essentially Zane's code, so I've confirmed that he's
> happy for me to send this, and am CCing this to him.
We'd need copyright assignment papers for something like this. Zane,
would you be willing to assign copyright for this code to the FSF?
diff --git a/lisp/bindings.el b/lisp/bindings.el
index a1751a253c..e2b4ceb08e 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -1418,6 +1418,9 @@ esc-map
(define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
(define-key ctl-x-4-map "c" 'clone-indirect-buffer-other-window)
+(define-key ctl-x-4-map "nn" 'narrow-to-region-indirect-other-window)
+(define-key ctl-x-4-map "np" 'narrow-to-page-indirect-other-window)
+(define-key ctl-x-4-map "nd" 'narrow-to-defun-indirect-other-window)
;; Signal handlers
(define-key special-event-map [sigusr1] 'ignore)
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index 8c18557c79..94edd8fdd6 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -647,6 +647,16 @@ narrow-to-defun
(re-search-backward "^\n" (- (point) 1) t)
(narrow-to-region beg end))))
+(defun narrow-to-defun-indirect-other-window (&optional arg)
+ "`narrow-to-defun' in a cloned indirect buffer in the other window.
+
+See `clone-indirect-buffer'."
+ (interactive)
+ (let ((buf (clone-indirect-buffer nil nil)))
+ (with-current-buffer buf
+ (narrow-to-defun arg))
+ (pop-to-buffer buf)))
+
(defcustom insert-pair-alist
'((?\( ?\)) (?\[ ?\]) (?\{ ?\}) (?\< ?\>) (?\" ?\") (?\' ?\') (?\` ?\'))
"Alist of paired characters inserted by `insert-pair'.
diff --git a/lisp/simple.el b/lisp/simple.el
index 7dc695848b..8e360a0076 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -8947,6 +8947,16 @@ clone-indirect-buffer-other-window
(let ((pop-up-windows t))
(clone-indirect-buffer newname display-flag norecord)))
+(defun narrow-to-region-indirect-other-window (start end)
+ "`narrow-to-region' in a cloned indirect buffer in the other window.
+
+See `clone-indirect-buffer'."
+ (interactive "r")
+ (deactivate-mark)
+ (let ((buf (clone-indirect-buffer nil nil)))
+ (with-current-buffer buf
+ (narrow-to-region start end))
+ (pop-to-buffer buf)))
;;; Handling of Backspace and Delete keys.
diff --git a/lisp/textmodes/page.el b/lisp/textmodes/page.el
index 029ba96691..e729c020a7 100644
--- a/lisp/textmodes/page.el
+++ b/lisp/textmodes/page.el
@@ -143,6 +143,16 @@ page--count-lines-page
(count-lines (point) opoint)
(count-lines opoint end))))))
+(defun narrow-to-page-indirect-other-window (&optional arg)
+ "`narrow-to-page' in a cloned indirect buffer in the other window.
+
+See `clone-indirect-buffer'."
+ (interactive "P")
+ (let ((buf (clone-indirect-buffer nil nil)))
+ (with-current-buffer buf
+ (narrow-to-page arg))
+ (pop-to-buffer buf)))
+
(defun count-lines-page ()
"Report number of lines on current page, and how many are before or after point."
(interactive)
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Added tag(s) moreinfo.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Fri, 18 Sep 2020 13:58:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#17401
; Package
emacs
.
(Fri, 18 Sep 2020 16:03:01 GMT)
Full text and
rfc822 format available.
Message #28 received at 17401 <at> debbugs.gnu.org (full text, mbox):
> > That post provides a function which creates a indirect clone of
> > the current buffer, and narrows to the marked region in that, so
> > that you have both the original un-narrowed buffer and the narrowed
> > indirect clone available simultaneously.
> >
> > This is incredibly useful, and it seems like an obvious contender
> > for standard functionality in Emacs.
> >
> > I'm attaching a patch which uses that approach to implement the
> > following functions and bindings:
> >
> > C-x 4 n n: narrow-to-region-indirect-other-window
> > C-x 4 n p: narrow-to-page-indirect-other-window
> > C-x 4 n d: narrow-to-defun-indirect-other-window
>
> Sounds like a good idea to me, and seems to be a logical extension.
> Anybody got an opinion?
>
> However:
>
> > It's still essentially Zane's code, so I've confirmed that he's
> > happy for me to send this, and am CCing this to him.
>
> We'd need copyright assignment papers for something like this. Zane,
> would you be willing to assign copyright for this code to the FSF?
FWIW, `narrow-indirect.el' is based on this and extends
it in a few ways. From the Commentary (and the wiki page):
;; Acknowledgments:
;;
;; The idea and original code for a command that combines narrowing
;; with cloning a buffer as an indirect-buffer is due to Zane Ashby:
;; https://demonastery.org/2013/04/emacs-narrow-to-region-indirect/.
;;
;; In Emacs bug thread #17401, Phil Sainty proposed adding three
;; commands to Emacs based on this approach. Lennart Borgman
;; contributed code that uses, in the cloned buffer name, some text
;; based on the narrowed region.
;;
;; The code in `narrow-indirect.el' extends this a bit and provides
;; a couple of user options and some alternative (prefix-argument)
;; behavior. It is doubtful that Emacs Dev will ever adopt features
;; such as those defined here, and if they do then this library can
;; at least help for Emacs versions prior to their addition.
Description here:
https://www.emacswiki.org/emacs/NarrowIndirect
Code:
https://www.emacswiki.org/emacs/download/narrow-indirect.el
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#17401
; Package
emacs
.
(Sat, 19 Sep 2020 04:34:02 GMT)
Full text and
rfc822 format available.
Message #31 received at 17401 <at> debbugs.gnu.org (full text, mbox):
More than happy to assign copyright to the FSF for this code, if someone can kindly point me in the right direction? :)
On Fri, Sep 18, 2020, at 1:57 PM, Lars Ingebrigtsen wrote:
>
> We'd need copyright assignment papers for something like this. Zane,
> would you be willing to assign copyright for this code to the FSF?
>
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#17401
; Package
emacs
.
(Sat, 19 Sep 2020 14:15:02 GMT)
Full text and
rfc822 format available.
Message #34 received at 17401 <at> debbugs.gnu.org (full text, mbox):
"Zane Ashby" <contact <at> zaneashby.co.nz> writes:
> More than happy to assign copyright to the FSF for this code, if
> someone can kindly point me in the right direction? :)
(Form sent off-list.)
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Removed tag(s) moreinfo.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Mon, 14 Dec 2020 17:15:02 GMT)
Full text and
rfc822 format available.
This bug report was last modified 4 years and 180 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.