mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-24 08:51:10 -08:00
Various improvements to auto-narrow mode.
* lisp/files.el (auto-narrow-display-length): Improve docstring. (auto-narrow-widen-automatically): Add 'undo' to the command list. (auto-narrow-hook): New defcustom. (auto-narrow-pre-command-function, auto-narrow-post-command-function): Move initialization code. (auto-narrow-mode): Do not make the 'auto-narrow-mode' permanent local anymore. * lisp/font-lock.el (turn-off-font-lock-mode): New convenience function. * src/xdisp.c (set_vertical_scroll_bar): Fix typo. (redisplay_window): Use the new convenience function. * src/buffer.h (BUFFER_NEEDS_AUTO_NARROWING_P, BUFFER_AUTO_NARROWED_NON_NARROWED_P): Two new convenience functions. * src/window.c (Frecenter): Do not recenter auto-narrowed buffers that are not actually narrowed. * etc/NEWS: Improvement. * doc/emacs/display.texi (Auto-Narrowing): Improvement.
This commit is contained in:
parent
38b3780f6e
commit
eb6d2fb58d
7 changed files with 68 additions and 22 deletions
|
|
@ -474,9 +474,10 @@ it. @xref{Disabling}.
|
||||||
@vindex auto-narrow-long-line-threshold
|
@vindex auto-narrow-long-line-threshold
|
||||||
@vindex auto-narrow-display-length
|
@vindex auto-narrow-display-length
|
||||||
@vindex auto-narrow-widen-automatically
|
@vindex auto-narrow-widen-automatically
|
||||||
|
@vindex auto-narrow-hook
|
||||||
|
|
||||||
When a file with extremely long lines is opened or inserted in a
|
When a file with extremely long lines is opened or inserted in a
|
||||||
buffer, Emacs automatically enters auto-narrow mode, and the word
|
buffer, Emacs automatically enters Auto-Narrow mode, and the word
|
||||||
@samp{Auto-Narrow} appears in the mode line. This means that Emacs
|
@samp{Auto-Narrow} appears in the mode line. This means that Emacs
|
||||||
restricts display, but not editing, to a portion of the buffer above
|
restricts display, but not editing, to a portion of the buffer above
|
||||||
and below point. All editing commands, including narrowing commands,
|
and below point. All editing commands, including narrowing commands,
|
||||||
|
|
@ -485,12 +486,21 @@ remain available, and they act on the whole buffer. For example,
|
||||||
happen with ordinary narrowing, to the end of the portion of the
|
happen with ordinary narrowing, to the end of the portion of the
|
||||||
buffer to which display is currently restricted.
|
buffer to which display is currently restricted.
|
||||||
|
|
||||||
The behavior of auto-narrow mode is controlled by three variables:
|
The behavior of Auto-Narrow mode is controlled by four variables:
|
||||||
@code{auto-narrow-long-line-threshold} is the line length above which
|
@code{auto-narrow-long-line-threshold} is the line length above which
|
||||||
auto-narrow move is entered, @code{auto-narrow-display-length} is the
|
Auto-Narrow move is entered, @code{auto-narrow-display-length} is the
|
||||||
number of characters to which display is restricted, and
|
number of characters to which display is restricted,
|
||||||
@code{auto-narrow-widen-automatically} is a list of commands for which
|
@code{auto-narrow-widen-automatically} is a list of commands for which
|
||||||
display is widened before they are executed.
|
display is widened before they are executed, and
|
||||||
|
@code{auto-narrow-hook} is a list of functions that are called when
|
||||||
|
Auto-Narrow mode is entered. By default, Font Lock mode is disabled
|
||||||
|
in Auto-Narrow mode.
|
||||||
|
|
||||||
|
If you still experience slowdowns while editing a file when
|
||||||
|
Auto-Narrow mode is enabled, this is not due to Emacs itself, but to
|
||||||
|
the current major mode or one of the enabled minor modes, and you
|
||||||
|
should open the file with @kbd{M-x find-file-literally} instead of
|
||||||
|
@kbd{C-x C-f}.
|
||||||
|
|
||||||
@node View Mode
|
@node View Mode
|
||||||
@section View Mode
|
@section View Mode
|
||||||
|
|
|
||||||
13
etc/NEWS
13
etc/NEWS
|
|
@ -905,10 +905,15 @@ automatically enters auto-narrow mode. This means that Emacs
|
||||||
restricts display, but not editing, to a portion of the buffer above
|
restricts display, but not editing, to a portion of the buffer above
|
||||||
and below point. All editing commands, including narrowing commands,
|
and below point. All editing commands, including narrowing commands,
|
||||||
remain available, and they act on the whole buffer. The behavior of
|
remain available, and they act on the whole buffer. The behavior of
|
||||||
that mode is controlled by three variables:
|
that mode is controlled by four variables:
|
||||||
auto-narrow-long-line-threshold, auto-narrow-display-length and
|
auto-narrow-long-line-threshold, auto-narrow-display-length,
|
||||||
auto-narrow-widen-automatically. To disable that feature, set
|
auto-narrow-widen-automatically and auto-narrow-hook (which by default
|
||||||
auto-narrow-long-line-threshold to nil in your init file.
|
disables font-lock-mode). To disable that feature, set
|
||||||
|
auto-narrow-long-line-threshold to nil in your init file. If you
|
||||||
|
still experience slowdowns while editing a file in auto-narrow mode,
|
||||||
|
this is due to the current major mode or one of the enabled minor
|
||||||
|
modes: you should open the file with M-x find-file-literally instead
|
||||||
|
of C-x C-f.
|
||||||
|
|
||||||
---
|
---
|
||||||
** 'zap-to-char' and 'zap-up-to-char' are case-sensitive for upper-case chars.
|
** 'zap-to-char' and 'zap-up-to-char' are case-sensitive for upper-case chars.
|
||||||
|
|
|
||||||
|
|
@ -2692,9 +2692,9 @@ the file contents into it using `insert-file-contents-literally'."
|
||||||
"Number of characters to which display is restricted in `auto-narrow-mode'.
|
"Number of characters to which display is restricted in `auto-narrow-mode'.
|
||||||
|
|
||||||
When `auto-narrow-mode' is in effect, the number of characters
|
When `auto-narrow-mode' is in effect, the number of characters
|
||||||
displayed above and below point is one third of
|
displayed above and below point is at least one third and at most
|
||||||
`auto-narrow-display-line-length', except at the beginning and
|
two thirds of `auto-narrow-display-line-length', except at the
|
||||||
end of the buffer."
|
beginning and end of the buffer."
|
||||||
:group 'files
|
:group 'files
|
||||||
:group 'find-file
|
:group 'find-file
|
||||||
:version "29.1"
|
:version "29.1"
|
||||||
|
|
@ -2706,13 +2706,20 @@ end of the buffer."
|
||||||
beginning-of-buffer end-of-buffer goto-char goto-line
|
beginning-of-buffer end-of-buffer goto-char goto-line
|
||||||
mark-sexp mark-defun mark-paragraph mark-whole-buffer mark-page
|
mark-sexp mark-defun mark-paragraph mark-whole-buffer mark-page
|
||||||
exchange-point-and-mark pop-global-mark set-mark-command jump-to-register
|
exchange-point-and-mark pop-global-mark set-mark-command jump-to-register
|
||||||
bookmark-jump)
|
bookmark-jump undo)
|
||||||
"Commands for which display is automatically widened in `auto-narrow-mode'."
|
"Commands for which display is automatically widened in `auto-narrow-mode'."
|
||||||
:group 'files
|
:group 'files
|
||||||
:group 'find-file
|
:group 'find-file
|
||||||
:version "29.1"
|
:version "29.1"
|
||||||
:type '(repeat function))
|
:type '(repeat function))
|
||||||
|
|
||||||
|
(defcustom auto-narrow-hook '(turn-off-font-lock-mode)
|
||||||
|
"List of functions to be called when `auto-narrow-mode' is entered."
|
||||||
|
:group 'find-file
|
||||||
|
:type 'hook
|
||||||
|
:version "29.1"
|
||||||
|
:type '(repeat function))
|
||||||
|
|
||||||
(defvar-local auto-narrow--widen-automatically nil
|
(defvar-local auto-narrow--widen-automatically nil
|
||||||
"Internal variable used by `auto-narrow-mode'.")
|
"Internal variable used by `auto-narrow-mode'.")
|
||||||
|
|
||||||
|
|
@ -2725,11 +2732,6 @@ end of the buffer."
|
||||||
(defun auto-narrow-pre-command-function ()
|
(defun auto-narrow-pre-command-function ()
|
||||||
"Conditionally widen display when `auto-narrow-mode' is in effect."
|
"Conditionally widen display when `auto-narrow-mode' is in effect."
|
||||||
(when auto-narrow-mode
|
(when auto-narrow-mode
|
||||||
(unless auto-narrow--initialized
|
|
||||||
(setq auto-narrow--widen-automatically widen-automatically
|
|
||||||
auto-narrow--isearch-widen-automatically isearch-widen-automatically
|
|
||||||
auto-narrow--narrowing-state 'auto
|
|
||||||
auto-narrow--initialized t))
|
|
||||||
(setq-local widen-automatically t
|
(setq-local widen-automatically t
|
||||||
isearch-widen-automatically t)
|
isearch-widen-automatically t)
|
||||||
(if (memq this-command '(narrow-to-region narrow-to-defun narrow-to-page))
|
(if (memq this-command '(narrow-to-region narrow-to-defun narrow-to-page))
|
||||||
|
|
@ -2747,7 +2749,11 @@ end of the buffer."
|
||||||
(when (and auto-narrow-mode
|
(when (and auto-narrow-mode
|
||||||
(not (eq auto-narrow--narrowing-state 'explicit)))
|
(not (eq auto-narrow--narrowing-state 'explicit)))
|
||||||
(unless auto-narrow--initialized
|
(unless auto-narrow--initialized
|
||||||
(setq auto-narrow--narrowing-state 'auto))
|
(run-hooks 'auto-narrow-hook)
|
||||||
|
(setq auto-narrow--widen-automatically widen-automatically
|
||||||
|
auto-narrow--isearch-widen-automatically isearch-widen-automatically
|
||||||
|
auto-narrow--narrowing-state 'auto
|
||||||
|
auto-narrow--initialized t))
|
||||||
(let (point cur-point-min buf-point-min buf-point-max size)
|
(let (point cur-point-min buf-point-min buf-point-max size)
|
||||||
(setq point (point) cur-point-min (point-min)
|
(setq point (point) cur-point-min (point-min)
|
||||||
size (/ auto-narrow-display-length 3))
|
size (/ auto-narrow-display-length 3))
|
||||||
|
|
@ -2777,7 +2783,6 @@ in a buffer. It restricts display, but not editing, to
|
||||||
executing any of the commands listed in `auto-narrow-widen-automatically'."
|
executing any of the commands listed in `auto-narrow-widen-automatically'."
|
||||||
:group 'files
|
:group 'files
|
||||||
:version "29.1"
|
:version "29.1"
|
||||||
:after-hook (progn (put 'auto-narrow-mode 'permanent-local t))
|
|
||||||
(if auto-narrow-mode
|
(if auto-narrow-mode
|
||||||
(auto-narrow-post-command-function)
|
(auto-narrow-post-command-function)
|
||||||
(when (not (eq auto-narrow--narrowing-state 'explicit))
|
(when (not (eq auto-narrow--narrowing-state 'explicit))
|
||||||
|
|
|
||||||
|
|
@ -2045,6 +2045,11 @@ Sets various variables using `font-lock-defaults' and
|
||||||
(setq font-lock-keywords
|
(setq font-lock-keywords
|
||||||
(font-lock-compile-keywords font-lock-keywords))))
|
(font-lock-compile-keywords font-lock-keywords))))
|
||||||
(font-lock-flush)))
|
(font-lock-flush)))
|
||||||
|
|
||||||
|
(defun turn-off-font-lock-mode ()
|
||||||
|
"Unconditionally turn off `font-lock-mode'."
|
||||||
|
(interactive)
|
||||||
|
(font-lock-mode -1))
|
||||||
|
|
||||||
;;; Color etc. support.
|
;;; Color etc. support.
|
||||||
|
|
||||||
|
|
|
||||||
16
src/buffer.h
16
src/buffer.h
|
|
@ -1120,12 +1120,28 @@ BUFFER_CHECK_INDIRECTION (struct buffer *b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check the state of auto-narrowed buffers. */
|
||||||
|
|
||||||
|
INLINE bool
|
||||||
|
BUFFER_NEEDS_AUTO_NARROWING_P (struct buffer *b)
|
||||||
|
{
|
||||||
|
return EQ (BVAR (b, auto_narrow__narrowing_state), Qneeded);
|
||||||
|
}
|
||||||
|
|
||||||
INLINE bool
|
INLINE bool
|
||||||
BUFFER_AUTO_NARROWED_P (struct buffer *b)
|
BUFFER_AUTO_NARROWED_P (struct buffer *b)
|
||||||
{
|
{
|
||||||
return EQ (BVAR (b, auto_narrow__narrowing_state), Qauto);
|
return EQ (BVAR (b, auto_narrow__narrowing_state), Qauto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INLINE bool
|
||||||
|
BUFFER_AUTO_NARROWED_NON_NARROWED_P (struct buffer *b)
|
||||||
|
{
|
||||||
|
return BUFFER_AUTO_NARROWED_P (b)
|
||||||
|
&& BUF_BEG (b) == BUF_BEGV (b)
|
||||||
|
&& BUF_Z (b) == BUF_ZV (b);
|
||||||
|
}
|
||||||
|
|
||||||
/* This structure holds the default values of the buffer-local variables
|
/* This structure holds the default values of the buffer-local variables
|
||||||
that have special slots in each buffer.
|
that have special slots in each buffer.
|
||||||
The default value occupies the same slot in this structure
|
The default value occupies the same slot in this structure
|
||||||
|
|
|
||||||
|
|
@ -6557,6 +6557,11 @@ and redisplay normally--don't erase and redraw the frame. */)
|
||||||
if (buf != current_buffer)
|
if (buf != current_buffer)
|
||||||
error ("`recenter'ing a window that does not display current-buffer.");
|
error ("`recenter'ing a window that does not display current-buffer.");
|
||||||
|
|
||||||
|
/* Refuse to recenter auto-narrowed buffers that are not actually narrowed,
|
||||||
|
as this can be very slow. */
|
||||||
|
if (BUFFER_AUTO_NARROWED_NON_NARROWED_P (buf))
|
||||||
|
return Qnil;
|
||||||
|
|
||||||
/* If redisplay is suppressed due to an error, try again. */
|
/* If redisplay is suppressed due to an error, try again. */
|
||||||
buf->display_error_modiff = 0;
|
buf->display_error_modiff = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18872,7 +18872,7 @@ set_vertical_scroll_bar (struct window *w)
|
||||||
&& NILP (echo_area_buffer[0])))
|
&& NILP (echo_area_buffer[0])))
|
||||||
{
|
{
|
||||||
struct buffer *buf = XBUFFER (w->contents);
|
struct buffer *buf = XBUFFER (w->contents);
|
||||||
if (! BUFFER_AUTO_NARROWED_P (current_buffer))
|
if (! BUFFER_AUTO_NARROWED_P (buf))
|
||||||
{
|
{
|
||||||
whole = BUF_ZV (buf) - BUF_BEGV (buf);
|
whole = BUF_ZV (buf) - BUF_BEGV (buf);
|
||||||
start = marker_position (w->start) - BUF_BEGV (buf);
|
start = marker_position (w->start) - BUF_BEGV (buf);
|
||||||
|
|
@ -19142,7 +19142,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p)
|
||||||
variables. */
|
variables. */
|
||||||
set_buffer_internal_1 (XBUFFER (w->contents));
|
set_buffer_internal_1 (XBUFFER (w->contents));
|
||||||
|
|
||||||
if (EQ (BVAR (current_buffer, auto_narrow__narrowing_state), Qneeded))
|
if (BUFFER_NEEDS_AUTO_NARROWING_P (current_buffer))
|
||||||
{
|
{
|
||||||
safe_call (1, Qauto_narrow_mode);
|
safe_call (1, Qauto_narrow_mode);
|
||||||
/* Normally set by auto-narrow-mode, set it here anyway as a safety measure. */
|
/* Normally set by auto-narrow-mode, set it here anyway as a safety measure. */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue