emacs-devel
[Top][All Lists]
Advanced

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

widen-one-level [was: Emacs's handling of line numbers]


From: Drew Adams
Subject: widen-one-level [was: Emacs's handling of line numbers]
Date: Sun, 18 Apr 2010 11:15:58 -0700

> One thing I've sometimes thought would be handy is an 
> additional widening command, `widen-one-level', which
> would widen only as far as the next-to-last narrowing. 
> 
> You can narrow and then narrow further, any number of times. 
> But `widen' always widens completely. Sometimes I would like
> to just undo the last level of narrowing, returning to the
> previous level (or to the top level, if there is
> only one narrowing).
> 
> This would require managing a list or stack of narrowing
> limits etc.
> 
> I have no idea whether anyone else would find such a command 
> useful. And I can't really characterize useful use cases.
> But I know I've sometimes wanted such a feature.


If you want to get a quick idea what this would be like, eval this code and bind
`widen-one-level' (e.g. to `C-x n w' ;-)).

---

(defvar restriction-stack () "Stack of buffer restrictions.")
(make-variable-buffer-local 'restriction-stack)

(defun widen-one-level (top)
  "Widen to the previous buffer restriction.
With a prefix argument, widen completely."
  (interactive "P")
  (unless restriction-stack
    (error "Cannot widen; buffer is not narrowed"))
  (if top
      (widen)
    (pop restriction-stack)
    (if (null restriction-stack)
        (widen)
      (narrow-to-region (caar restriction-stack)
                        (cdar restriction-stack))
      (pop restriction-stack))))
(defadvice narrow-to-region (before push-restriction-stack activate)
  (setq restriction-stack  (cons (cons start end) restriction-stack))
  (when (and (= start 1) (= end (1+ (buffer-size))))
    (setq restriction-stack  ())))

(defadvice widen (before empty-restriction-stack activate)
  (setq restriction-stack  ()))

; (define-key ctl-x-map "nw" 'widen-one-level)

---

Another possibility would be to make a restriction ring, instead of a stack, and
let you browse among the restrictions...





reply via email to

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