bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#17401: 24.4.50; Narrow to {region,page,defun} in an indirect clone b


From: Lennart Borgman
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

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]