unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window
@ 2014-05-04 10:38 Phil Sainty
  2014-05-04 13:43 ` Drew Adams
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Phil Sainty @ 2014-05-04 10:38 UTC (permalink / raw)
  To: 17401; +Cc: contact

[-- Attachment #1: Type: text/plain, Size: 3453 bytes --]

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))



[-- Attachment #2: narrow-indirect-other-buffer.patch --]
[-- Type: text/plain, Size: 2790 bytes --]

diff --git a/lisp/bindings.el b/lisp/bindings.el
index 7093b8e..e8352ef 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -1270,6 +1270,9 @@ if `inhibit-field-text-motion' is non-nil."
 
 (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 3ff65ff..7119ef6 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -556,6 +556,16 @@ Optional ARG is ignored."
       (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)))
+
 (defvar insert-pair-alist
   '((?\( ?\)) (?\[ ?\]) (?\{ ?\}) (?\< ?\>) (?\" ?\") (?\' ?\') (?\` ?\'))
   "Alist of paired characters inserted by `insert-pair'.
diff --git a/lisp/simple.el b/lisp/simple.el
index 1484339..156d1bd 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -7570,6 +7570,16 @@ front of the list of recently selected ones."
   (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)))
 \f
 ;;; Handling of Backspace and Delete keys.
 
diff --git a/lisp/textmodes/page.el b/lisp/textmodes/page.el
index d535108..866e96a 100644
--- a/lisp/textmodes/page.el
+++ b/lisp/textmodes/page.el
@@ -125,6 +125,16 @@ thus showing a page other than the one point was originally in."
 			(point)))))
 (put 'narrow-to-page 'disabled t)
 
+(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)

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window
  2014-05-04 10:38 bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window Phil Sainty
@ 2014-05-04 13:43 ` Drew Adams
  2014-05-08  0:05 ` Lennart Borgman
  2020-09-18 13:57 ` Lars Ingebrigtsen
  2 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2014-05-04 13:43 UTC (permalink / raw)
  To: Phil Sainty, 17401; +Cc: contact

+1





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window
  2014-05-04 10:38 bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window Phil Sainty
  2014-05-04 13:43 ` Drew Adams
@ 2014-05-08  0:05 ` Lennart Borgman
  2014-05-10 13:06   ` Phil Sainty
  2020-09-18 13:57 ` Lars Ingebrigtsen
  2 siblings, 1 reply; 10+ messages in thread
From: Lennart Borgman @ 2014-05-08  0:05 UTC (permalink / raw)
  To: Phil Sainty; +Cc: 17401, contact

[-- Attachment #1: Type: text/plain, Size: 4958 bytes --]

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@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))
>
>
>

[-- Attachment #2: Type: text/html, Size: 6287 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window
  2014-05-08  0:05 ` Lennart Borgman
@ 2014-05-10 13:06   ` Phil Sainty
  2014-05-10 20:57     ` Josh
  2014-05-11  4:12     ` Drew Adams
  0 siblings, 2 replies; 10+ messages in thread
From: Phil Sainty @ 2014-05-10 13:06 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: 17401, contact

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







^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window
  2014-05-10 13:06   ` Phil Sainty
@ 2014-05-10 20:57     ` Josh
  2014-05-11  4:12     ` Drew Adams
  1 sibling, 0 replies; 10+ messages in thread
From: Josh @ 2014-05-10 20:57 UTC (permalink / raw)
  To: Phil Sainty; +Cc: 17401, contact

On Sat, May 10, 2014 at 6:06 AM, Phil Sainty <psainty@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'?





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window
  2014-05-10 13:06   ` Phil Sainty
  2014-05-10 20:57     ` Josh
@ 2014-05-11  4:12     ` Drew Adams
  1 sibling, 0 replies; 10+ messages in thread
From: Drew Adams @ 2014-05-11  4:12 UTC (permalink / raw)
  To: Phil Sainty, Lennart Borgman; +Cc: 17401, contact

[-- Attachment #1: Type: text/plain, Size: 2220 bytes --]

> 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)

[-- Attachment #2: narrow-other.el --]
[-- Type: application/octet-stream, Size: 3744 bytes --]

(defcustom narrowed-buf-name-max 60
  "Max length of cloned indirect buffer name, for narrowing commands."
  :type '(restricted-sexp :tag "Max length of buffer name"
          :match-alternatives ((lambda (x) (and (integerp x)  (> x 0))))
          :value ignore)
  :group 'editing)

(defcustom narrowed-buf-name-prefix ""
  "Name prefix for indirect buffer cloned by `narrow-*-indirect*' commands.
Using a non-empty prefix lets you easily distinguish the indirect
buffers from the original."
  :type 'string :group 'editing)

(defun narrow-to-defun-indirect-other-window (&optional full-name text)
  "`narrow-to-defun' in a cloned indirect buffer in the other window.
The name of the indirect buffer depends on the use of a prefix arg:

* No prefix arg: the current buffer name, but with ` | NAME'
  appended, where NAME is the name of the object defined by the defun.

* Prefix arg < 0 : like no prefix arg, but you are prompted for NAME.

* Prefix arg >= 0: you are prompted for the full buffer name.

However, the buffer name is in any case truncated at
`narrowed-buf-name-max' chars.

Non-interactively:
* FULL-NAME is the full buffer name, and TEXT is ignored.
* TEXT is used for NAME, if FULL-NAME is nil.

See `clone-indirect-buffer'."
  (interactive
   (list (and current-prefix-arg
              (natnump (prefix-numeric-value current-prefix-arg))
              (read-string "Buffer name: "))
         (and current-prefix-arg
              (< (prefix-numeric-value current-prefix-arg) 0)
              (read-string "Buffer name suffix: "))))
  (require 'which-func)
  (let ((here  (point)))
    (mark-defun)
    (narrow-to-region-indirect-other-window
     (region-beginning) (region-end) here full-name
     (and (not full-name)  (or text  (which-function))))))
     
(defun narrow-to-region-indirect-other-window (start end here
                                               &optional full-name text msgp)
  "`narrow-to-region' in a cloned indirect buffer in the other window.
The indirect buffer is named the same as the current buffer, except:

 * It is prefixed by the value of option `narrowed-buf-name-prefix'.
 * It is suffixed by ` | TEXT', where TEXT is the region text.

However, the buffer name is in any case truncated at
`narrowed-buf-name-max' chars.

Non-interactively:
START and END are the region beginning and end.
HERE is where to place the cursor, relative to START.
TEXT is prefixed by ` | ' and appended to the original
 buffer name, which is appended to `narrowed-buf-name-prefix' to name
 the new buffer.
If FULL-NAME is a string then it is used as the complete indirect
buffer name.  (TEXT is then ignored.)

See `clone-indirect-buffer'."
  (interactive
   (list (region-beginning) (region-end) (point)
         (and current-prefix-arg  (read-string "Buffer name: "))
         nil 'MSGP))
  (if (and (= start end)  msgp)
      (message "Region is empty")
    (deactivate-mark)
    (let* ((buf  (or full-name
                     text
                     (replace-regexp-in-string
                      "\\(\s \\)+" "\1"
                      (replace-regexp-in-string
                       "\\`\s+\\|\s+\\'" ""
                       (buffer-substring-no-properties start end)))))
           (buf  (or full-name
                     (concat narrowed-buf-name-prefix (buffer-name) " | " buf)))
           (buf  (or full-name
                     (substring buf 0 (min (length buf) narrowed-buf-name-max))))
           (buf  (clone-indirect-buffer buf nil)))
      (with-current-buffer buf (narrow-to-region start end) (goto-char here))
      (pop-to-buffer buf))))

(define-key ctl-x-4-map "nn" 'narrow-to-region-indirect-other-window)
(define-key ctl-x-4-map "nd" 'narrow-to-defun-indirect-other-window)


^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window
  2014-05-04 10:38 bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window Phil Sainty
  2014-05-04 13:43 ` Drew Adams
  2014-05-08  0:05 ` Lennart Borgman
@ 2020-09-18 13:57 ` Lars Ingebrigtsen
  2020-09-18 16:02   ` Drew Adams
  2020-09-18 21:22   ` Zane Ashby
  2 siblings, 2 replies; 10+ messages in thread
From: Lars Ingebrigtsen @ 2020-09-18 13:57 UTC (permalink / raw)
  To: Phil Sainty; +Cc: 17401, contact

Phil Sainty <psainty@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)))
 \f
 ;;; 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





^ permalink raw reply related	[flat|nested] 10+ messages in thread

* bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window
  2020-09-18 13:57 ` Lars Ingebrigtsen
@ 2020-09-18 16:02   ` Drew Adams
  2020-09-18 21:22   ` Zane Ashby
  1 sibling, 0 replies; 10+ messages in thread
From: Drew Adams @ 2020-09-18 16:02 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Phil Sainty; +Cc: 17401, contact

> > 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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window
  2020-09-18 13:57 ` Lars Ingebrigtsen
  2020-09-18 16:02   ` Drew Adams
@ 2020-09-18 21:22   ` Zane Ashby
  2020-09-19 14:14     ` Lars Ingebrigtsen
  1 sibling, 1 reply; 10+ messages in thread
From: Zane Ashby @ 2020-09-18 21:22 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Phil Sainty; +Cc: 17401

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?
> 





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window
  2020-09-18 21:22   ` Zane Ashby
@ 2020-09-19 14:14     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 10+ messages in thread
From: Lars Ingebrigtsen @ 2020-09-19 14:14 UTC (permalink / raw)
  To: Zane Ashby; +Cc: Phil Sainty, 17401

"Zane Ashby" <contact@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





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-09-19 14:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-04 10:38 bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window Phil Sainty
2014-05-04 13:43 ` Drew Adams
2014-05-08  0:05 ` Lennart Borgman
2014-05-10 13:06   ` Phil Sainty
2014-05-10 20:57     ` Josh
2014-05-11  4:12     ` Drew Adams
2020-09-18 13:57 ` Lars Ingebrigtsen
2020-09-18 16:02   ` Drew Adams
2020-09-18 21:22   ` Zane Ashby
2020-09-19 14:14     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).