From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lennart Borgman Newsgroups: gmane.emacs.bugs Subject: bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone buffer in the other window Date: Thu, 8 May 2014 02:05:33 +0200 Message-ID: References: <53661891.40206@orcon.net.nz> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c36692c8817804f8d83f80 X-Trace: ger.gmane.org 1399507642 12150 80.91.229.3 (8 May 2014 00:07:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 8 May 2014 00:07:22 +0000 (UTC) Cc: 17401@debbugs.gnu.org, contact@zaneashby.co.nz To: Phil Sainty Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu May 08 02:07:16 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WiBro-0003Kr-8q for geb-bug-gnu-emacs@m.gmane.org; Thu, 08 May 2014 02:07:16 +0200 Original-Received: from localhost ([::1]:44079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiBrn-0000rb-Pl for geb-bug-gnu-emacs@m.gmane.org; Wed, 07 May 2014 20:07:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiBrf-0000rP-I5 for bug-gnu-emacs@gnu.org; Wed, 07 May 2014 20:07:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WiBrb-0001QV-9H for bug-gnu-emacs@gnu.org; Wed, 07 May 2014 20:07:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37601) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiBrb-0001QL-5I for bug-gnu-emacs@gnu.org; Wed, 07 May 2014 20:07:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1WiBra-00068v-Hp for bug-gnu-emacs@gnu.org; Wed, 07 May 2014 20:07:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lennart Borgman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 08 May 2014 00:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17401 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 17401-submit@debbugs.gnu.org id=B17401.139950758323560 (code B ref 17401); Thu, 08 May 2014 00:07:02 +0000 Original-Received: (at 17401) by debbugs.gnu.org; 8 May 2014 00:06:23 +0000 Original-Received: from localhost ([127.0.0.1]:54952 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WiBqw-00067r-PD for submit@debbugs.gnu.org; Wed, 07 May 2014 20:06:23 -0400 Original-Received: from mail-we0-f171.google.com ([74.125.82.171]:43968) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WiBqt-00067c-Bj for 17401@debbugs.gnu.org; Wed, 07 May 2014 20:06:20 -0400 Original-Received: by mail-we0-f171.google.com with SMTP id w62so1774692wes.30 for <17401@debbugs.gnu.org>; Wed, 07 May 2014 17:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=mCc8xyXZrsTRXTpVV2WXCSt7Mz5OAJbxCqM2JI15lG0=; b=wCSX+UcdYbdnalyD8Ag/Nayrn5eBNS8dkoqi1GMMwifkmTAVDOeb69lWLHQ2JTHRNZ 1CZiF6j5g/brVhwz49Z2L7ldgG4IY0ymJjQt/8fOBeBMeA0DS4zSREp8nOb/+h4NpGe8 HyJMZXBPTrDx7sq1oPOoWMV1z0msd95iA0u71qu85AWdupPKka9gAQKGU5qOKC4cRNuY a3HJIIT7DdPkueeNnIssuT6isPqlY1gOboy/DnDV8iG4hC24DOqHr3S94/uC+ojZ4j4n 1x56nYy/nu2yDkQvLctIM0DttCnyT5rphjsaMPqZaxRhHhdrfdSQdT6N8G6Uue3mGnkz GOqg== X-Received: by 10.180.12.238 with SMTP id b14mr717038wic.16.1399507573570; Wed, 07 May 2014 17:06:13 -0700 (PDT) Original-Received: by 10.195.12.201 with HTTP; Wed, 7 May 2014 17:05:33 -0700 (PDT) In-Reply-To: <53661891.40206@orcon.net.nz> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:88761 Archived-At: --001a11c36692c8817804f8d83f80 Content-Type: text/plain; charset=UTF-8 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 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: > M-x r e p o r t - e m > > 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)) > > > --001a11c36692c8817804f8d83f80 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Here is my current version (which I think perhaps Phil can= make something better of):

(defun narrow-to-region-indirect (s= tart end here name-suffix)
=C2=A0 "Restrict editing in this = buffer to the current region, indirectly."
=C2=A0 (interactive (list (region-beginning) (region-end) (region-begi= nning) ""))
=C2=A0 (deactivate-mark)
=C2=A0 (= let ((posdiff (- here start))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (name (= buffer-name))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (line name-suffix))
=C2=A0 =C2=A0 (save-excursion
=C2=A0 =C2=A0 =C2=A0 (goto-cha= r start)
=C2=A0 =C2=A0 =C2=A0 (while (and (not (eobp)) (string=3D= line ""))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq line (buff= er-substring-no-properties (point-at-bol) (point-at-eol)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq line (replace-regexp-in-string "= ;^\s+\\|\s+$" "" line))
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 (forward-line)))
=C2=A0 =C2=A0 (let* ((bn (concat name "= <" line ">"))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0(buf (clone-indirect-buffer bn nil)))
=C2=A0 =C2=A0 =C2=A0 (with-current-buffer buf
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 (narrow-to-region start end)
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 (goto-char start)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (forward-cha= r posdiff))
=C2=A0 =C2=A0 =C2=A0 (switch-to-buffer buf))))
<= div>
(defun narrow-to-defun-indirect ()
=C2=A0 "Restrict edi= ting in this buffer to the current function, indirectly."
= =C2=A0 (interactive)
=C2=A0 (require 'which-func)
= =C2=A0 (let ((here (point))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (suffix (which-function)))
=C2= =A0 =C2=A0 (mark-defun)
=C2=A0 =C2=A0 (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, becaus= e
I was doing this manually on a regular basis.

http://demonastery.org/2013/04/emacs-narrow-to-region-in= direct/

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&#= 39;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)
=C2=A0of 2014-05-03 on xerxes
Windowing system distributor `The X.Org Foundation', version 11.0.11300= 000
System Description: =C2=A0 =C2=A0 Ubuntu 12.04.4 LTS

Configured using:
=C2=A0`configure --prefix=3D/usr/local/src/emacs/usr/local --without-sound&= #39;

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK DBUS GSETTINGS NOTIFY GNUTLS
LIBXML2 FREETYPE XFT ZLIB

Important settings:
=C2=A0 value of $LANG: en_NZ.UTF-8
=C2=A0 locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
=C2=A0 tooltip-mode: t
=C2=A0 electric-indent-mode: t
=C2=A0 mouse-wheel-mode: t
=C2=A0 tool-bar-mode: t
=C2=A0 menu-bar-mode: t
=C2=A0 file-name-shadow-mode: t
=C2=A0 global-font-lock-mode: t
=C2=A0 font-lock-mode: t
=C2=A0 blink-cursor-mode: t
=C2=A0 auto-composition-mode: t
=C2=A0 auto-encryption-mode: t
=C2=A0 auto-compression-mode: t
=C2=A0 line-number-mode: t
=C2=A0 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)
=C2=A0(symbols 48 17834 0)
=C2=A0(miscs 40 35 138)
=C2=A0(strings 32 10321 4869)
=C2=A0(string-bytes 1 288458)
=C2=A0(vectors 16 9191)
=C2=A0(vector-slots 8 374331 12806)
=C2=A0(floats 8 63 98)
=C2=A0(intervals 56 170 0)
=C2=A0(buffers 960 11)
=C2=A0(heap 1024 19710 771))



--001a11c36692c8817804f8d83f80--