* 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.
@vindex auto-narrow-long-line-threshold
@vindex auto-narrow-display-length
@vindex auto-narrow-widen-automatically
+@vindex auto-narrow-hook
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
restricts display, but not editing, to a portion of the buffer above
and below point. All editing commands, including narrowing commands,
happen with ordinary narrowing, to the end of the portion of the
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
-auto-narrow move is entered, @code{auto-narrow-display-length} is the
-number of characters to which display is restricted, and
+Auto-Narrow move is entered, @code{auto-narrow-display-length} is the
+number of characters to which display is restricted,
@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
@section View Mode
restricts display, but not editing, to a portion of the buffer above
and below point. All editing commands, including narrowing commands,
remain available, and they act on the whole buffer. The behavior of
-that mode is controlled by three variables:
-auto-narrow-long-line-threshold, auto-narrow-display-length and
-auto-narrow-widen-automatically. To disable that feature, set
-auto-narrow-long-line-threshold to nil in your init file.
+that mode is controlled by four variables:
+auto-narrow-long-line-threshold, auto-narrow-display-length,
+auto-narrow-widen-automatically and auto-narrow-hook (which by default
+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.
"Number of characters to which display is restricted in `auto-narrow-mode'.
When `auto-narrow-mode' is in effect, the number of characters
-displayed above and below point is one third of
-`auto-narrow-display-line-length', except at the beginning and
-end of the buffer."
+displayed above and below point is at least one third and at most
+two thirds of `auto-narrow-display-line-length', except at the
+beginning and end of the buffer."
:group 'files
:group 'find-file
:version "29.1"
beginning-of-buffer end-of-buffer goto-char goto-line
mark-sexp mark-defun mark-paragraph mark-whole-buffer mark-page
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'."
:group 'files
:group 'find-file
:version "29.1"
: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
"Internal variable used by `auto-narrow-mode'.")
(defun auto-narrow-pre-command-function ()
"Conditionally widen display when `auto-narrow-mode' is in effect."
(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
isearch-widen-automatically t)
(if (memq this-command '(narrow-to-region narrow-to-defun narrow-to-page))
(when (and auto-narrow-mode
(not (eq auto-narrow--narrowing-state 'explicit)))
(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)
(setq point (point) cur-point-min (point-min)
size (/ auto-narrow-display-length 3))
executing any of the commands listed in `auto-narrow-widen-automatically'."
:group 'files
:version "29.1"
- :after-hook (progn (put 'auto-narrow-mode 'permanent-local t))
(if auto-narrow-mode
(auto-narrow-post-command-function)
(when (not (eq auto-narrow--narrowing-state 'explicit))
(setq font-lock-keywords
(font-lock-compile-keywords font-lock-keywords))))
(font-lock-flush)))
+
+(defun turn-off-font-lock-mode ()
+ "Unconditionally turn off `font-lock-mode'."
+ (interactive)
+ (font-lock-mode -1))
\f
;;; Color etc. support.
}
}
+/* 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
BUFFER_AUTO_NARROWED_P (struct buffer *b)
{
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
that have special slots in each buffer.
The default value occupies the same slot in this structure
if (buf != 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. */
buf->display_error_modiff = 0;
&& NILP (echo_area_buffer[0])))
{
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);
start = marker_position (w->start) - BUF_BEGV (buf);
variables. */
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);
/* Normally set by auto-narrow-mode, set it here anyway as a safety measure. */