[Top][All Lists]
[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...
- Re: Emacs's handling of line numbers [from bug#5042], Mark Lillibridge, 2010/04/11
- Re: Emacs's handling of line numbers [from bug#5042], Stefan Monnier, 2010/04/11
- Re: Emacs's handling of line numbers [from bug#5042], Mark Lillibridge, 2010/04/17
- Re: Emacs's handling of line numbers [from bug#5042], Eli Zaretskii, 2010/04/17
- Re: Emacs's handling of line numbers [from bug#5042], Stefan Monnier, 2010/04/17
- Re: Emacs's handling of line numbers [from bug#5042], Eli Zaretskii, 2010/04/17
- Re: Emacs's handling of line numbers [from bug#5042], Mark Lillibridge, 2010/04/17
- Re: Emacs's handling of line numbers [from bug#5042], Eli Zaretskii, 2010/04/17
- Re: Emacs's handling of line numbers [from bug#5042], Juanma Barranquero, 2010/04/17
- RE: Emacs's handling of line numbers [from bug#5042], Drew Adams, 2010/04/17
- widen-one-level [was: Emacs's handling of line numbers],
Drew Adams <=
- Re: widen-one-level [was: Emacs's handling of line numbers], Juri Linkov, 2010/04/18
- RE: widen-one-level [was: Emacs's handling of line numbers], Drew Adams, 2010/04/18
- Re: widen-one-level [was: Emacs's handling of line numbers], Davis Herring, 2010/04/18
- Re: widen-one-level [was: Emacs's handling of line numbers], Richard Stallman, 2010/04/19
- RE: widen-one-level [was: Emacs's handling of line numbers], Drew Adams, 2010/04/19
- Re: widen-one-level [was: Emacs's handling of line numbers], Juri Linkov, 2010/04/19
- Re: widen-one-level [was: Emacs's handling of line numbers], Leo, 2010/04/18
- RE: widen-one-level [was: Emacs's handling of line numbers], Drew Adams, 2010/04/18
- Re: widen-one-level [was: Emacs's handling of line numbers], Leo, 2010/04/19
- RE: widen-one-level [was: Emacs's handling of line numbers], Drew Adams, 2010/04/19