From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Phil Sainty 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: Sun, 04 May 2014 22:38:09 +1200 Message-ID: <53661891.40206@orcon.net.nz> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090900020107060507090508" X-Trace: ger.gmane.org 1399200039 18630 80.91.229.3 (4 May 2014 10:40:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 4 May 2014 10:40:39 +0000 (UTC) Cc: contact@zaneashby.co.nz To: 17401@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun May 04 12:40:26 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 1WgtqG-0007WU-SO for geb-bug-gnu-emacs@m.gmane.org; Sun, 04 May 2014 12:40:21 +0200 Original-Received: from localhost ([::1]:52887 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgtqG-0004R6-D0 for geb-bug-gnu-emacs@m.gmane.org; Sun, 04 May 2014 06:40:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42679) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wgtq6-0004Qn-DH for bug-gnu-emacs@gnu.org; Sun, 04 May 2014 06:40:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wgtpz-00080r-KD for bug-gnu-emacs@gnu.org; Sun, 04 May 2014 06:40:10 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:33027) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wgtpz-0007zl-H0 for bug-gnu-emacs@gnu.org; Sun, 04 May 2014 06:40:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Wgtpz-0005I6-2a for bug-gnu-emacs@gnu.org; Sun, 04 May 2014 06:40:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Phil Sainty Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 04 May 2014 10:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 17401 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.139919996020253 (code B ref -1); Sun, 04 May 2014 10:40:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 4 May 2014 10:39:20 +0000 Original-Received: from localhost ([127.0.0.1]:50378 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WgtpH-0005Ga-Ib for submit@debbugs.gnu.org; Sun, 04 May 2014 06:39:20 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:40743) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WgtpE-0005GC-5W for submit@debbugs.gnu.org; Sun, 04 May 2014 06:39:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wgtp2-0007g8-Gf for submit@debbugs.gnu.org; Sun, 04 May 2014 06:39:11 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:44358) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wgtp2-0007g4-Dh for submit@debbugs.gnu.org; Sun, 04 May 2014 06:39:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42414) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wgtow-0004GM-2c for bug-gnu-emacs@gnu.org; Sun, 04 May 2014 06:39:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wgtoq-0007dC-0v for bug-gnu-emacs@gnu.org; Sun, 04 May 2014 06:38:58 -0400 Original-Received: from nctlincom01.orcon.net.nz ([60.234.4.69]:46454) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wgtop-0007cL-Fv for bug-gnu-emacs@gnu.org; Sun, 04 May 2014 06:38:51 -0400 Original-Received: from mx9.orcon.net.nz (mx9.orcon.net.nz [219.88.242.59]) by nctlincom01.orcon.net.nz (8.14.3/8.14.3/Debian-9.4) with ESMTP id s44AheDf023505; Sun, 4 May 2014 22:43:40 +1200 Original-Received: from 121-99-136-8.bng1.tvc.orcon.net.nz ([121.99.136.8] helo=[10.1.1.5]) by mx9.orcon.net.nz with esmtpa (Exim 4.69) (envelope-from ) id 1Wgtoi-0004RH-CM; Sun, 04 May 2014 22:38:44 +1200 User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN, default) X-CanIt-Geo: ip=121.99.136.8; country=NZ; latitude=-41.0000; longitude=174.0000; http://maps.google.com/maps?q=-41.0000,174.0000&z=6 X-CanItPRO-Stream: base:default X-Canit-Stats-ID: 06LVKHEEo - a697450d8bf0 - 20140504 X-Scanned-By: CanIt (www . roaringpenguin . com) on 172.16.100.174 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). 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:88626 Archived-At: This is a multi-part message in MIME format. --------------090900020107060507090508 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit 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)) --------------090900020107060507090508 Content-Type: text/plain; charset=windows-1252; name="narrow-indirect-other-buffer.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="narrow-indirect-other-buffer.patch" 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))) ;;; 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) --------------090900020107060507090508--