* src/dispextern.h (struct it): New 'narrowed_begv' field.
* src/dispextern.h (WITH_NARROWED_BEGV): New macro.
* src/xdisp.c (get_narrowed_begv): New function.
(init_iterator): Initilize the 'narrowed_begv' field.
(back_to_previous_line_start, get_visually_first_element,
move_it_vertically_backward): Use the new macro.
* src/dispextern.h: Prototype of 'get_narrowed_begv'.
* src/window.c (window_body_height): Make it externally visible.
* src/window.h: Prototype of 'window_body_height'.
* src/composite.c (find_automatic_composition): Optimize display in buffers
with very long lines with 'get_narrowed_begv'.
* lisp/obsolete/longlines.el: Reobsolete longlines-mode.
* etc/NEWS: Announce the new minor mode, and remove the unobsoletion
indication for 'longlines-mode'.
* doc/emacs/trouble.texi (Long Lines): Remove the section.
(Lossage): Remove the entry for the Long Lines section.
* doc/emacs/emacs.texi (Top): Remove the entry for the Long Lines section.
* Crashing:: What Emacs does when it crashes.
* After a Crash:: Recovering editing in an Emacs session that crashed.
* Emergency Escape:: What to do if Emacs stops responding.
-* Long Lines:: Mitigating slowness due to extremely long lines.
* DEL Does Not Delete:: What to do if @key{DEL} doesn't delete.
Reporting Bugs
* Crashing:: What Emacs does when it crashes.
* After a Crash:: Recovering editing in an Emacs session that crashed.
* Emergency Escape:: What to do if Emacs stops responding.
-* Long Lines:: Mitigating slowness due to extremely long lines.
* DEL Does Not Delete:: What to do if @key{DEL} doesn't delete.
@end menu
emergency escape---but there are cases where it won't work, when a
system call hangs or when Emacs is stuck in a tight loop in C code.
-@node Long Lines
-@subsection Long Lines
-@cindex long lines
-
- For a variety of reasons (some of which are fundamental to the Emacs
-redisplay code and the complex range of possibilities it handles;
-others of which are due to modes and features which do not scale well
-in unusual circumstances), Emacs can perform poorly when extremely
-long lines are present (where ``extremely long'' usually means at
-least many thousands of characters).
-
-@cindex @code{so-long} mode
-@findex global-so-long-mode
-@vindex so-long-action
- A particular problem is that Emacs may ``hang'' for a long time at
-the point of visiting a file with extremely long lines. This can be
-mitigated by enabling the @file{so-long} library, which detects when a
-visited file contains abnormally long lines, and takes steps to
-disable features which are liable to cause slowness in that situation.
-To enable this library, type @kbd{M-x global-so-long-mode @key{RET}},
-or turn on the @code{global-so-long-mode} in your init file
-(@pxref{Init File}), or customize the @code{global-so-long-mode}
-option. You can tailor this mode's operation by customizing the
-variable @code{so-long-action}.
-
- The @file{so-long} library can also significantly improve
-performance when moving and editing in a buffer with long lines.
-Performance is still likely to degrade as you get deeper into the long
-lines, but the improvements from using this library can nevertheless
-be substantial.
-
-@findex so-long-commentary
- Use @kbd{M-x so-long-commentary} to view the documentation for this
-library and learn more about how to enable and configure it.
-
-@vindex max-redisplay-ticks
- If even @code{so-long-mode} doesn't help making Emacs responsive
-enough, or if you'd rather not disable the display-related features
-that @code{so-long-mode} turns off, you can instead customize the
-variable @code{max-redisplay-ticks} to a non-zero value. Then Emacs
-will abort redisplay of a window and commands, like @kbd{C-n} and
-@kbd{M-v}, which use the display code to do their job, if processing a
-window needs more low-level display operations than the value of this
-variable. The display of the offending window will then remain
-outdated, and possibly incomplete, on the screen, but Emacs should
-otherwise be responsive, and you could then switch to another buffer,
-or kill the problematic buffer, or turn on @code{so-long-mode} or
-@code{so-long-minor-mode} in that buffer. When the display of a
-window is aborted due to this reason, the buffer shown in that window
-will not have any of its windows redisplayed until the buffer is
-modified or until you type @kbd{C-l} (@pxref{Recentering}) in one of
-that buffer's windows.
-
- If you decide to customize this variable to a non-zero value, we
-recommend to use a value between 100,000 and 1,000,000, depending on
-your patience and the speed of your system. The default value is
-zero, which disables this feature.
-
@node DEL Does Not Delete
@subsection If @key{DEL} Fails to Delete
@cindex @key{DEL} vs @key{BACKSPACE}
* Changes in Emacs 29.1
---
-** 'longlines-mode' is no longer obsolete.
+** Emacs is now capable of editing files with arbitarily long lines.
+The display of long lines has been optimized, and Emacs no longer
+chokes when a buffer on display contains long lines. If you still
+experience slowdowns while editing files with long lines, this is
+either due to font locking, which you can turn off with M-x
+font-lock-mode, or to the current major mode or one of the enabled
+minor modes, in which case you should open the the file with M-x
+find-file-literally instead of C-x C-f.
+++
** New command to change the font size globally.
This variable is used by some operations (mostly syntax-propertization
and font-locking) to treat lines longer than this variable as if they
were made up of various smaller lines. This can help reduce the
-pathological slowdowns seen in buffers made of a single long line, but
-can also cause misbehavior in the presence of such long lines (tho
-most of that misbehavior should usually be limited to mis-highlighting).
-You can recover the previous behavior with:
+slowdowns seen in buffers made of a single long line, but can also
+cause misbehavior in the presence of such long lines (tho most of that
+misbehavior should usually be limited to mis-highlighting). You can
+recover the previous behavior with:
(setq syntax-wholeline-max most-positive-fixnum)
previous behavior). The default is nil, which inhibits recording of
passwords.
-+++
-** New user option 'longlines-breakpoint-chars'.
-This is a string containing chars that could be used as breakpoint in
-longlines mode.
-
+++
** New function 'command-query'.
This function makes its argument command prompt the user for
+++ /dev/null
-;;; longlines.el --- automatically wrap long lines -*- lexical-binding: t; -*-
-
-;; Copyright (C) 2000-2001, 2004-2022 Free Software Foundation, Inc.
-
-;; Authors: Kai Grossjohann <Kai.Grossjohann@CS.Uni-Dortmund.DE>
-;; Alex Schroeder <alex@gnu.org>
-;; Chong Yidong <cyd@stupidchicken.com>
-;; Maintainer: emacs-devel@gnu.org
-;; Keywords: convenience, wp
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Some text editors save text files with long lines, and they
-;; automatically break these lines at whitespace, without actually
-;; inserting any newline characters. When doing `M-q' in Emacs, you
-;; are inserting newline characters. Longlines mode provides a file
-;; format which wraps the long lines when reading a file and unwraps
-;; the lines when saving the file. It can also wrap and unwrap
-;; automatically as editing takes place.
-
-;; Special thanks to Rod Smith for many useful bug reports.
-
-;;; Code:
-;;; Options
-
-(defgroup longlines nil
- "Automatic wrapping of long lines when loading files."
- :group 'fill)
-
-(defcustom longlines-auto-wrap t
- "Non-nil means long lines are automatically wrapped after each command.
-Otherwise, you can perform filling using `fill-paragraph' or
-`auto-fill-mode'. In any case, the soft newlines will be removed
-when the file is saved to disk."
- :type 'boolean)
-
-(defcustom longlines-wrap-follows-window-size nil
- "Non-nil means wrapping and filling happen at the edge of the window.
-Otherwise, `fill-column' is used, regardless of the window size. This
-does not work well when the buffer is displayed in multiple windows
-with differing widths.
-
-If the value is an integer, that specifies the distance from the
-right edge of the window at which wrapping occurs. For any other
-non-nil value, wrapping occurs 2 characters from the right edge."
- :type 'boolean)
-
-(defcustom longlines-show-hard-newlines nil
- "Non-nil means each hard newline is marked on the screen.
-\(The variable `longlines-show-effect' controls what they look like.)
-You can also enable the display temporarily, using the command
-`longlines-show-hard-newlines'."
- :type 'boolean)
-
-(defcustom longlines-show-effect (propertize "ΒΆ\n" 'face 'escape-glyph)
- "A string to display when showing hard newlines.
-This is used when `longlines-show-hard-newlines' is on."
- :type 'string)
-
-(defcustom longlines-breakpoint-chars " ;,|"
- "A bag of separator chars for longlines."
- :type 'string)
-
-;;; Internal variables
-
-(defvar longlines-wrap-beg nil)
-(defvar longlines-wrap-end nil)
-(defvar longlines-wrap-point nil)
-(defvar longlines-showing nil)
-(defvar longlines-decoded nil)
-
-(make-variable-buffer-local 'longlines-wrap-beg)
-(make-variable-buffer-local 'longlines-wrap-end)
-(make-variable-buffer-local 'longlines-wrap-point)
-(make-variable-buffer-local 'longlines-showing)
-(make-variable-buffer-local 'longlines-decoded)
-
-;;; Mode
-
-(defvar message-indent-citation-function)
-
-;;;###autoload
-(define-minor-mode longlines-mode
- "Toggle Long Lines mode in this buffer.
-
-When Long Lines mode is enabled, long lines are wrapped if they
-extend beyond `fill-column'. The soft newlines used for line
-wrapping will not show up when the text is yanked or saved to
-disk.
-
-If the variable `longlines-auto-wrap' is non-nil, lines are
-automatically wrapped whenever the buffer is changed. You can
-always call `fill-paragraph' to fill individual paragraphs.
-
-If the variable `longlines-show-hard-newlines' is non-nil, hard
-newlines are indicated with a symbol."
- :lighter " ll"
- (if longlines-mode
- ;; Turn on longlines mode
- (progn
- (use-hard-newlines 1 'never)
- (set (make-local-variable 'require-final-newline) nil)
- (add-to-list 'buffer-file-format 'longlines)
- (add-hook 'change-major-mode-hook #'longlines-mode-off nil t)
- (add-hook 'before-revert-hook #'longlines-before-revert-hook nil t)
- (make-local-variable 'buffer-substring-filters)
- (make-local-variable 'longlines-auto-wrap)
- (set (make-local-variable 'isearch-search-fun-function)
- #'longlines-search-function)
- (set (make-local-variable 'replace-search-function)
- #'longlines-search-forward)
- (set (make-local-variable 'replace-re-search-function)
- #'longlines-re-search-forward)
- (add-to-list 'buffer-substring-filters 'longlines-encode-string)
- (when longlines-wrap-follows-window-size
- (let ((dw (if (and (integerp longlines-wrap-follows-window-size)
- (>= longlines-wrap-follows-window-size 0)
- (< longlines-wrap-follows-window-size
- (window-width)))
- longlines-wrap-follows-window-size
- 2)))
- (set (make-local-variable 'fill-column)
- (- (window-width) dw)))
- (add-hook 'window-configuration-change-hook
- #'longlines-window-change-function nil t))
- (let ((buffer-undo-list t)
- (inhibit-read-only t)
- (inhibit-modification-hooks t)
- (mod (buffer-modified-p))
- buffer-file-name buffer-file-truename)
- ;; Turning off undo is OK since (spaces + newlines) is
- ;; conserved, except for a corner case in
- ;; longlines-wrap-lines that we'll never encounter from here
- (save-restriction
- (widen)
- (unless longlines-decoded
- (longlines-decode-buffer)
- (setq longlines-decoded t))
- (longlines-wrap-region (point-min) (point-max)))
- (set-buffer-modified-p mod))
- (when (and longlines-show-hard-newlines
- (not longlines-showing))
- (longlines-show-hard-newlines))
-
- ;; Hacks to make longlines play nice with various modes.
- (cond ((eq major-mode 'mail-mode)
- (declare-function mail-indent-citation "sendmail" ())
- (add-hook 'mail-setup-hook #'longlines-decode-buffer nil t)
- (or mail-citation-hook
- (add-hook 'mail-citation-hook #'mail-indent-citation nil t))
- (add-hook 'mail-citation-hook #'longlines-decode-region nil t))
- ((eq major-mode 'message-mode)
- (add-hook 'message-setup-hook #'longlines-decode-buffer nil t)
- (make-local-variable 'message-indent-citation-function)
- (if (not (listp message-indent-citation-function))
- (setq message-indent-citation-function
- (list message-indent-citation-function)))
- (add-hook 'message-indent-citation-function
- #'longlines-decode-region t t)))
-
- (add-hook 'after-change-functions #'longlines-after-change-function nil t)
- (add-hook 'post-command-hook #'longlines-post-command-function nil t)
- (when longlines-auto-wrap
- (auto-fill-mode 0)))
- ;; Turn off longlines mode
- (setq buffer-file-format (delete 'longlines buffer-file-format))
- (if longlines-showing
- (longlines-unshow-hard-newlines))
- (let ((buffer-undo-list t)
- (inhibit-modification-hooks t)
- (inhibit-read-only t)
- buffer-file-name buffer-file-truename)
- (if longlines-decoded
- (save-restriction
- (widen)
- (longlines-encode-region (point-min) (point-max))
- (setq longlines-decoded nil))))
- (remove-hook 'change-major-mode-hook #'longlines-mode-off t)
- (remove-hook 'after-change-functions #'longlines-after-change-function t)
- (remove-hook 'post-command-hook #'longlines-post-command-function t)
- (remove-hook 'before-revert-hook #'longlines-before-revert-hook t)
- (remove-hook 'window-configuration-change-hook
- #'longlines-window-change-function t)
- (when longlines-wrap-follows-window-size
- (kill-local-variable 'fill-column))
- (kill-local-variable 'isearch-search-fun-function)
- (kill-local-variable 'replace-search-function)
- (kill-local-variable 'replace-re-search-function)
- (kill-local-variable 'require-final-newline)
- (kill-local-variable 'buffer-substring-filters)
- (kill-local-variable 'use-hard-newlines)))
-
-(defun longlines-mode-off ()
- "Turn off longlines mode.
-This function exists to be called by `change-major-mode-hook' when the
-major mode changes."
- (longlines-mode 0))
-
-;;; Showing the effect of hard newlines in the buffer
-
-(defun longlines-show-hard-newlines (&optional arg)
- "Make hard newlines visible by adding a face.
-With optional argument ARG, make the hard newlines invisible again."
- (interactive "P")
- (if arg
- (longlines-unshow-hard-newlines)
- (setq longlines-showing t)
- (longlines-show-region (point-min) (point-max))))
-
-(defun longlines-show-region (beg end)
- "Make hard newlines between BEG and END visible."
- (let* ((pmin (min beg end))
- (pmax (max beg end))
- (pos (text-property-not-all pmin pmax 'hard nil))
- (mod (buffer-modified-p))
- (buffer-undo-list t)
- (inhibit-read-only t)
- (inhibit-modification-hooks t)
- buffer-file-name buffer-file-truename)
- (while pos
- (put-text-property pos (1+ pos) 'display
- (copy-sequence longlines-show-effect))
- (setq pos (text-property-not-all (1+ pos) pmax 'hard nil)))
- (restore-buffer-modified-p mod)))
-
-(defun longlines-unshow-hard-newlines ()
- "Make hard newlines invisible again."
- (interactive)
- (setq longlines-showing nil)
- (let ((pos (text-property-not-all (point-min) (point-max) 'hard nil))
- (mod (buffer-modified-p))
- (buffer-undo-list t)
- (inhibit-read-only t)
- (inhibit-modification-hooks t)
- buffer-file-name buffer-file-truename)
- (while pos
- (remove-text-properties pos (1+ pos) '(display nil))
- (setq pos (text-property-not-all (1+ pos) (point-max) 'hard nil)))
- (restore-buffer-modified-p mod)))
-
-;;; Wrapping the paragraphs
-
-(defun longlines-wrap-region (beg end)
- "Wrap each successive line, starting with the line before BEG.
-Stop when we reach lines after END that don't need wrapping, or the
-end of the buffer."
- (let ((mod (buffer-modified-p)))
- (setq longlines-wrap-point (point))
- (goto-char beg)
- (forward-line -1)
- ;; Two successful longlines-wrap-line's in a row mean successive
- ;; lines don't need wrapping.
- (while (null (and (longlines-wrap-line)
- (or (eobp)
- (and (>= (point) end)
- (longlines-wrap-line))))))
- (goto-char longlines-wrap-point)
- (set-buffer-modified-p mod)))
-
-(defun longlines-wrap-line ()
- "If the current line needs to be wrapped, wrap it and return nil.
-If wrapping is performed, point remains on the line. If the line does
-not need to be wrapped, move point to the next line and return t."
- (if (longlines-set-breakpoint fill-column)
- (progn (insert-before-markers-and-inherit ?\n)
- nil)
- (if (longlines-merge-lines-p)
- (progn (end-of-line)
- ;; After certain commands (e.g. kill-line), there may be two
- ;; successive soft newlines in the buffer. In this case, we
- ;; replace these two newlines by a single space. Unfortunately,
- ;; this breaks the conservation of (spaces + newlines), so we
- ;; have to fiddle with longlines-wrap-point.
- (if (or (prog1 (bolp) (forward-char 1)) (eolp))
- (progn
- (delete-char -1)
- (if (> longlines-wrap-point (point))
- (setq longlines-wrap-point
- (1- longlines-wrap-point))))
- (delete-char -1))
- nil)
- (forward-line 1)
- t)))
-
-(defun longlines-set-breakpoint (target-column)
- "Place point where we should break the current line, and return t.
-If the line should not be broken, return nil; point remains on the
-line."
- (move-to-column target-column)
- (let ((non-breakpoint-re (format "[^%s]" longlines-breakpoint-chars)))
- (if (and (re-search-forward non-breakpoint-re (line-end-position) t 1)
- (> (current-column) target-column))
- ;; This line is too long. Can we break it?
- (or (longlines-find-break-backward)
- (progn (move-to-column target-column)
- (longlines-find-break-forward))))))
-
-(defun longlines-find-break-backward ()
- "Move point backward to the first available breakpoint and return t.
-If no breakpoint is found, return nil."
- (let ((breakpoint-re (format "[%s]" longlines-breakpoint-chars)))
- (when (and (re-search-backward breakpoint-re (line-beginning-position) t 1)
- (save-excursion
- (skip-chars-backward longlines-breakpoint-chars
- (line-beginning-position))
- (null (bolp))))
- (forward-char 1)
- (if (and fill-nobreak-predicate
- (run-hook-with-args-until-success 'fill-nobreak-predicate))
- (progn
- (skip-chars-backward longlines-breakpoint-chars
- (line-beginning-position))
- (longlines-find-break-backward))
- t))))
-
-(defun longlines-find-break-forward ()
- "Move point forward to the first available breakpoint and return t.
-If no break point is found, return nil."
- (let ((breakpoint-re (format "[%s]" longlines-breakpoint-chars)))
- (and (re-search-forward breakpoint-re (line-end-position) t 1)
- (progn
- (skip-chars-forward longlines-breakpoint-chars (line-end-position))
- (null (eolp)))
- (if (and fill-nobreak-predicate
- (run-hook-with-args-until-success 'fill-nobreak-predicate))
- (longlines-find-break-forward)
- t))))
-
-(defun longlines-merge-lines-p ()
- "Return t if part of the next line can fit onto the current line.
-Otherwise, return nil. Text cannot be moved across hard newlines."
- (save-excursion
- (end-of-line)
- (and (null (eobp))
- (null (get-text-property (point) 'hard))
- (let ((space (- fill-column (current-column))))
- (forward-line 1)
- (longlines-set-breakpoint (max 0 (1- space)))))))
-
-(defun longlines-decode-region (&optional beg end)
- "Turn all newlines between BEG and END into hard newlines.
-If BEG and END are nil, the point and mark are used."
- (if (null beg) (setq beg (point)))
- (if (null end) (setq end (mark t)))
- (save-excursion
- (let ((reg-max (max beg end)))
- (goto-char (min beg end))
- (while (search-forward "\n" reg-max t)
- (set-hard-newline-properties
- (match-beginning 0) (match-end 0))))))
-
-(defun longlines-decode-buffer ()
- "Turn all newlines in the buffer into hard newlines."
- (longlines-decode-region (point-min) (point-max)))
-
-(defun longlines-encode-region (beg end &optional _buffer)
- "Remove each soft newline between BEG and END.
-Hard newlines are left intact. The optional argument BUFFER exists for
-compatibility with `format-alist', and is ignored."
- (save-excursion
- (let ((reg-max (max beg end))
- (mod (buffer-modified-p)))
- (goto-char (min beg end))
- (while (search-forward "\n" reg-max t)
- (let ((pos (match-beginning 0)))
- (unless (get-text-property pos 'hard)
- (remove-text-properties pos (1+ pos) '(hard nil))
- (delete-region pos (1+ pos)))))
- (set-buffer-modified-p mod)
- end)))
-
-(defun longlines-encode-string (string)
- "Return a copy of STRING with each soft newline replaced by a space.
-Hard newlines are left intact."
- (let* ((str (copy-sequence string))
- (pos (string-search "\n" str)))
- (while pos
- (if (null (get-text-property pos 'hard str))
- (aset str pos ? ))
- (setq pos (string-search "\n" str (1+ pos))))
- str))
-
-;;; Auto wrap
-
-(defun longlines-auto-wrap (&optional arg)
- "Toggle automatic line wrapping.
-With optional argument ARG, turn on line wrapping if and only if
-ARG is positive.
-If automatic line wrapping is turned on, wrap the entire buffer."
- (interactive "P")
- (setq arg (if arg
- (> (prefix-numeric-value arg) 0)
- (not longlines-auto-wrap)))
- (if arg
- (progn
- (setq longlines-auto-wrap t)
- (longlines-wrap-region (point-min) (point-max))
- (message "Auto wrap enabled."))
- (setq longlines-auto-wrap nil)
- (message "Auto wrap disabled.")))
-
-(defun longlines-after-change-function (beg end _len)
- "Update `longlines-wrap-beg' and `longlines-wrap-end'.
-This is called by `after-change-functions' to keep track of the region
-that has changed."
- (when (and longlines-auto-wrap (not undo-in-progress))
- (setq longlines-wrap-beg
- (if longlines-wrap-beg (min longlines-wrap-beg beg) beg))
- (setq longlines-wrap-end
- (if longlines-wrap-end (max longlines-wrap-end end) end))))
-
-(defun longlines-post-command-function ()
- "Perform line wrapping on the parts of the buffer that have changed.
-This is called by `post-command-hook' after each command."
- (when (and longlines-auto-wrap longlines-wrap-beg)
- (if (or (eq this-command 'yank)
- (eq this-command 'yank-pop))
- (longlines-decode-region (point) (mark t)))
- (if longlines-showing
- (longlines-show-region longlines-wrap-beg longlines-wrap-end))
- (unless (or (eq this-command 'fill-paragraph)
- (eq this-command 'fill-region))
- (longlines-wrap-region longlines-wrap-beg longlines-wrap-end))
- (setq longlines-wrap-beg nil)
- (setq longlines-wrap-end nil)))
-
-(defun longlines-window-change-function ()
- "Re-wrap the buffer if the window width has changed.
-This is called by `window-configuration-change-hook'."
- (let ((dw (if (and (integerp longlines-wrap-follows-window-size)
- (>= longlines-wrap-follows-window-size 0)
- (< longlines-wrap-follows-window-size (window-width)))
- longlines-wrap-follows-window-size
- 2)))
- (when (/= fill-column (- (window-width) dw))
- (setq fill-column (- (window-width) dw))
- (longlines-wrap-region (point-min) (point-max)))))
-
-;;; Isearch
-
-(defun longlines-search-function ()
- (cond
- ((or isearch-regexp-function isearch-regexp) (isearch-search-fun-default))
- (isearch-forward #'longlines-search-forward)
- (t #'longlines-search-backward)))
-
-(defun longlines-search-forward (string &optional bound noerror count)
- (let ((search-spaces-regexp " *[ \n]"))
- (re-search-forward (regexp-quote string) bound noerror count)))
-
-(defun longlines-search-backward (string &optional bound noerror count)
- (let ((search-spaces-regexp " *[ \n]"))
- (re-search-backward (regexp-quote string) bound noerror count)))
-
-(defun longlines-re-search-forward (string &optional bound noerror count)
- (let ((search-spaces-regexp " *[ \n]"))
- (re-search-forward string bound noerror count)))
-
-;;; Loading and saving
-
-(defun longlines-before-revert-hook ()
- (add-hook 'after-revert-hook #'longlines-after-revert-hook nil t)
- (longlines-mode 0))
-
-(defun longlines-after-revert-hook ()
- (remove-hook 'after-revert-hook #'longlines-after-revert-hook t)
- (longlines-mode 1))
-
-(add-to-list
- 'format-alist
- (list 'longlines "Automatically wrap long lines." nil nil
- #'longlines-encode-region t nil))
-
-;;; Unloading
-
-(defun longlines-unload-function ()
- "Unload the longlines library."
- (save-current-buffer
- (dolist (buffer (buffer-list))
- (set-buffer buffer)
- (longlines-mode-off)))
- ;; continue standard unloading
- nil)
-
-(provide 'longlines)
-
-;;; longlines.el ends here
--- /dev/null
+;;; longlines.el --- automatically wrap long lines -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2000-2001, 2004-2022 Free Software Foundation, Inc.
+
+;; Authors: Kai Grossjohann <Kai.Grossjohann@CS.Uni-Dortmund.DE>
+;; Alex Schroeder <alex@gnu.org>
+;; Chong Yidong <cyd@stupidchicken.com>
+;; Maintainer: emacs-devel@gnu.org
+;; Obsolete-since: 24.4
+;; Keywords: convenience, wp
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Some text editors save text files with long lines, and they
+;; automatically break these lines at whitespace, without actually
+;; inserting any newline characters. When doing `M-q' in Emacs, you
+;; are inserting newline characters. Longlines mode provides a file
+;; format which wraps the long lines when reading a file and unwraps
+;; the lines when saving the file. It can also wrap and unwrap
+;; automatically as editing takes place.
+
+;; Special thanks to Rod Smith for many useful bug reports.
+
+;;; Code:
+;;; Options
+
+(defgroup longlines nil
+ "Automatic wrapping of long lines when loading files."
+ :group 'fill)
+
+(defcustom longlines-auto-wrap t
+ "Non-nil means long lines are automatically wrapped after each command.
+Otherwise, you can perform filling using `fill-paragraph' or
+`auto-fill-mode'. In any case, the soft newlines will be removed
+when the file is saved to disk."
+ :type 'boolean)
+
+(defcustom longlines-wrap-follows-window-size nil
+ "Non-nil means wrapping and filling happen at the edge of the window.
+Otherwise, `fill-column' is used, regardless of the window size. This
+does not work well when the buffer is displayed in multiple windows
+with differing widths.
+
+If the value is an integer, that specifies the distance from the
+right edge of the window at which wrapping occurs. For any other
+non-nil value, wrapping occurs 2 characters from the right edge."
+ :type 'boolean)
+
+(defcustom longlines-show-hard-newlines nil
+ "Non-nil means each hard newline is marked on the screen.
+\(The variable `longlines-show-effect' controls what they look like.)
+You can also enable the display temporarily, using the command
+`longlines-show-hard-newlines'."
+ :type 'boolean)
+
+(defcustom longlines-show-effect (propertize "ΒΆ\n" 'face 'escape-glyph)
+ "A string to display when showing hard newlines.
+This is used when `longlines-show-hard-newlines' is on."
+ :type 'string)
+
+(defcustom longlines-breakpoint-chars " ;,|"
+ "A bag of separator chars for longlines."
+ :type 'string)
+
+;;; Internal variables
+
+(defvar longlines-wrap-beg nil)
+(defvar longlines-wrap-end nil)
+(defvar longlines-wrap-point nil)
+(defvar longlines-showing nil)
+(defvar longlines-decoded nil)
+
+(make-variable-buffer-local 'longlines-wrap-beg)
+(make-variable-buffer-local 'longlines-wrap-end)
+(make-variable-buffer-local 'longlines-wrap-point)
+(make-variable-buffer-local 'longlines-showing)
+(make-variable-buffer-local 'longlines-decoded)
+
+;;; Mode
+
+(defvar message-indent-citation-function)
+
+;;;###autoload
+(define-minor-mode longlines-mode
+ "Toggle Long Lines mode in this buffer.
+
+When Long Lines mode is enabled, long lines are wrapped if they
+extend beyond `fill-column'. The soft newlines used for line
+wrapping will not show up when the text is yanked or saved to
+disk.
+
+If the variable `longlines-auto-wrap' is non-nil, lines are
+automatically wrapped whenever the buffer is changed. You can
+always call `fill-paragraph' to fill individual paragraphs.
+
+If the variable `longlines-show-hard-newlines' is non-nil, hard
+newlines are indicated with a symbol."
+ :lighter " ll"
+ (if longlines-mode
+ ;; Turn on longlines mode
+ (progn
+ (use-hard-newlines 1 'never)
+ (set (make-local-variable 'require-final-newline) nil)
+ (add-to-list 'buffer-file-format 'longlines)
+ (add-hook 'change-major-mode-hook #'longlines-mode-off nil t)
+ (add-hook 'before-revert-hook #'longlines-before-revert-hook nil t)
+ (make-local-variable 'buffer-substring-filters)
+ (make-local-variable 'longlines-auto-wrap)
+ (set (make-local-variable 'isearch-search-fun-function)
+ #'longlines-search-function)
+ (set (make-local-variable 'replace-search-function)
+ #'longlines-search-forward)
+ (set (make-local-variable 'replace-re-search-function)
+ #'longlines-re-search-forward)
+ (add-to-list 'buffer-substring-filters 'longlines-encode-string)
+ (when longlines-wrap-follows-window-size
+ (let ((dw (if (and (integerp longlines-wrap-follows-window-size)
+ (>= longlines-wrap-follows-window-size 0)
+ (< longlines-wrap-follows-window-size
+ (window-width)))
+ longlines-wrap-follows-window-size
+ 2)))
+ (set (make-local-variable 'fill-column)
+ (- (window-width) dw)))
+ (add-hook 'window-configuration-change-hook
+ #'longlines-window-change-function nil t))
+ (let ((buffer-undo-list t)
+ (inhibit-read-only t)
+ (inhibit-modification-hooks t)
+ (mod (buffer-modified-p))
+ buffer-file-name buffer-file-truename)
+ ;; Turning off undo is OK since (spaces + newlines) is
+ ;; conserved, except for a corner case in
+ ;; longlines-wrap-lines that we'll never encounter from here
+ (save-restriction
+ (widen)
+ (unless longlines-decoded
+ (longlines-decode-buffer)
+ (setq longlines-decoded t))
+ (longlines-wrap-region (point-min) (point-max)))
+ (set-buffer-modified-p mod))
+ (when (and longlines-show-hard-newlines
+ (not longlines-showing))
+ (longlines-show-hard-newlines))
+
+ ;; Hacks to make longlines play nice with various modes.
+ (cond ((eq major-mode 'mail-mode)
+ (declare-function mail-indent-citation "sendmail" ())
+ (add-hook 'mail-setup-hook #'longlines-decode-buffer nil t)
+ (or mail-citation-hook
+ (add-hook 'mail-citation-hook #'mail-indent-citation nil t))
+ (add-hook 'mail-citation-hook #'longlines-decode-region nil t))
+ ((eq major-mode 'message-mode)
+ (add-hook 'message-setup-hook #'longlines-decode-buffer nil t)
+ (make-local-variable 'message-indent-citation-function)
+ (if (not (listp message-indent-citation-function))
+ (setq message-indent-citation-function
+ (list message-indent-citation-function)))
+ (add-hook 'message-indent-citation-function
+ #'longlines-decode-region t t)))
+
+ (add-hook 'after-change-functions #'longlines-after-change-function nil t)
+ (add-hook 'post-command-hook #'longlines-post-command-function nil t)
+ (when longlines-auto-wrap
+ (auto-fill-mode 0)))
+ ;; Turn off longlines mode
+ (setq buffer-file-format (delete 'longlines buffer-file-format))
+ (if longlines-showing
+ (longlines-unshow-hard-newlines))
+ (let ((buffer-undo-list t)
+ (inhibit-modification-hooks t)
+ (inhibit-read-only t)
+ buffer-file-name buffer-file-truename)
+ (if longlines-decoded
+ (save-restriction
+ (widen)
+ (longlines-encode-region (point-min) (point-max))
+ (setq longlines-decoded nil))))
+ (remove-hook 'change-major-mode-hook #'longlines-mode-off t)
+ (remove-hook 'after-change-functions #'longlines-after-change-function t)
+ (remove-hook 'post-command-hook #'longlines-post-command-function t)
+ (remove-hook 'before-revert-hook #'longlines-before-revert-hook t)
+ (remove-hook 'window-configuration-change-hook
+ #'longlines-window-change-function t)
+ (when longlines-wrap-follows-window-size
+ (kill-local-variable 'fill-column))
+ (kill-local-variable 'isearch-search-fun-function)
+ (kill-local-variable 'replace-search-function)
+ (kill-local-variable 'replace-re-search-function)
+ (kill-local-variable 'require-final-newline)
+ (kill-local-variable 'buffer-substring-filters)
+ (kill-local-variable 'use-hard-newlines)))
+
+(defun longlines-mode-off ()
+ "Turn off longlines mode.
+This function exists to be called by `change-major-mode-hook' when the
+major mode changes."
+ (longlines-mode 0))
+
+;;; Showing the effect of hard newlines in the buffer
+
+(defun longlines-show-hard-newlines (&optional arg)
+ "Make hard newlines visible by adding a face.
+With optional argument ARG, make the hard newlines invisible again."
+ (interactive "P")
+ (if arg
+ (longlines-unshow-hard-newlines)
+ (setq longlines-showing t)
+ (longlines-show-region (point-min) (point-max))))
+
+(defun longlines-show-region (beg end)
+ "Make hard newlines between BEG and END visible."
+ (let* ((pmin (min beg end))
+ (pmax (max beg end))
+ (pos (text-property-not-all pmin pmax 'hard nil))
+ (mod (buffer-modified-p))
+ (buffer-undo-list t)
+ (inhibit-read-only t)
+ (inhibit-modification-hooks t)
+ buffer-file-name buffer-file-truename)
+ (while pos
+ (put-text-property pos (1+ pos) 'display
+ (copy-sequence longlines-show-effect))
+ (setq pos (text-property-not-all (1+ pos) pmax 'hard nil)))
+ (restore-buffer-modified-p mod)))
+
+(defun longlines-unshow-hard-newlines ()
+ "Make hard newlines invisible again."
+ (interactive)
+ (setq longlines-showing nil)
+ (let ((pos (text-property-not-all (point-min) (point-max) 'hard nil))
+ (mod (buffer-modified-p))
+ (buffer-undo-list t)
+ (inhibit-read-only t)
+ (inhibit-modification-hooks t)
+ buffer-file-name buffer-file-truename)
+ (while pos
+ (remove-text-properties pos (1+ pos) '(display nil))
+ (setq pos (text-property-not-all (1+ pos) (point-max) 'hard nil)))
+ (restore-buffer-modified-p mod)))
+
+;;; Wrapping the paragraphs
+
+(defun longlines-wrap-region (beg end)
+ "Wrap each successive line, starting with the line before BEG.
+Stop when we reach lines after END that don't need wrapping, or the
+end of the buffer."
+ (let ((mod (buffer-modified-p)))
+ (setq longlines-wrap-point (point))
+ (goto-char beg)
+ (forward-line -1)
+ ;; Two successful longlines-wrap-line's in a row mean successive
+ ;; lines don't need wrapping.
+ (while (null (and (longlines-wrap-line)
+ (or (eobp)
+ (and (>= (point) end)
+ (longlines-wrap-line))))))
+ (goto-char longlines-wrap-point)
+ (set-buffer-modified-p mod)))
+
+(defun longlines-wrap-line ()
+ "If the current line needs to be wrapped, wrap it and return nil.
+If wrapping is performed, point remains on the line. If the line does
+not need to be wrapped, move point to the next line and return t."
+ (if (longlines-set-breakpoint fill-column)
+ (progn (insert-before-markers-and-inherit ?\n)
+ nil)
+ (if (longlines-merge-lines-p)
+ (progn (end-of-line)
+ ;; After certain commands (e.g. kill-line), there may be two
+ ;; successive soft newlines in the buffer. In this case, we
+ ;; replace these two newlines by a single space. Unfortunately,
+ ;; this breaks the conservation of (spaces + newlines), so we
+ ;; have to fiddle with longlines-wrap-point.
+ (if (or (prog1 (bolp) (forward-char 1)) (eolp))
+ (progn
+ (delete-char -1)
+ (if (> longlines-wrap-point (point))
+ (setq longlines-wrap-point
+ (1- longlines-wrap-point))))
+ (delete-char -1))
+ nil)
+ (forward-line 1)
+ t)))
+
+(defun longlines-set-breakpoint (target-column)
+ "Place point where we should break the current line, and return t.
+If the line should not be broken, return nil; point remains on the
+line."
+ (move-to-column target-column)
+ (let ((non-breakpoint-re (format "[^%s]" longlines-breakpoint-chars)))
+ (if (and (re-search-forward non-breakpoint-re (line-end-position) t 1)
+ (> (current-column) target-column))
+ ;; This line is too long. Can we break it?
+ (or (longlines-find-break-backward)
+ (progn (move-to-column target-column)
+ (longlines-find-break-forward))))))
+
+(defun longlines-find-break-backward ()
+ "Move point backward to the first available breakpoint and return t.
+If no breakpoint is found, return nil."
+ (let ((breakpoint-re (format "[%s]" longlines-breakpoint-chars)))
+ (when (and (re-search-backward breakpoint-re (line-beginning-position) t 1)
+ (save-excursion
+ (skip-chars-backward longlines-breakpoint-chars
+ (line-beginning-position))
+ (null (bolp))))
+ (forward-char 1)
+ (if (and fill-nobreak-predicate
+ (run-hook-with-args-until-success 'fill-nobreak-predicate))
+ (progn
+ (skip-chars-backward longlines-breakpoint-chars
+ (line-beginning-position))
+ (longlines-find-break-backward))
+ t))))
+
+(defun longlines-find-break-forward ()
+ "Move point forward to the first available breakpoint and return t.
+If no break point is found, return nil."
+ (let ((breakpoint-re (format "[%s]" longlines-breakpoint-chars)))
+ (and (re-search-forward breakpoint-re (line-end-position) t 1)
+ (progn
+ (skip-chars-forward longlines-breakpoint-chars (line-end-position))
+ (null (eolp)))
+ (if (and fill-nobreak-predicate
+ (run-hook-with-args-until-success 'fill-nobreak-predicate))
+ (longlines-find-break-forward)
+ t))))
+
+(defun longlines-merge-lines-p ()
+ "Return t if part of the next line can fit onto the current line.
+Otherwise, return nil. Text cannot be moved across hard newlines."
+ (save-excursion
+ (end-of-line)
+ (and (null (eobp))
+ (null (get-text-property (point) 'hard))
+ (let ((space (- fill-column (current-column))))
+ (forward-line 1)
+ (longlines-set-breakpoint (max 0 (1- space)))))))
+
+(defun longlines-decode-region (&optional beg end)
+ "Turn all newlines between BEG and END into hard newlines.
+If BEG and END are nil, the point and mark are used."
+ (if (null beg) (setq beg (point)))
+ (if (null end) (setq end (mark t)))
+ (save-excursion
+ (let ((reg-max (max beg end)))
+ (goto-char (min beg end))
+ (while (search-forward "\n" reg-max t)
+ (set-hard-newline-properties
+ (match-beginning 0) (match-end 0))))))
+
+(defun longlines-decode-buffer ()
+ "Turn all newlines in the buffer into hard newlines."
+ (longlines-decode-region (point-min) (point-max)))
+
+(defun longlines-encode-region (beg end &optional _buffer)
+ "Remove each soft newline between BEG and END.
+Hard newlines are left intact. The optional argument BUFFER exists for
+compatibility with `format-alist', and is ignored."
+ (save-excursion
+ (let ((reg-max (max beg end))
+ (mod (buffer-modified-p)))
+ (goto-char (min beg end))
+ (while (search-forward "\n" reg-max t)
+ (let ((pos (match-beginning 0)))
+ (unless (get-text-property pos 'hard)
+ (remove-text-properties pos (1+ pos) '(hard nil))
+ (delete-region pos (1+ pos)))))
+ (set-buffer-modified-p mod)
+ end)))
+
+(defun longlines-encode-string (string)
+ "Return a copy of STRING with each soft newline replaced by a space.
+Hard newlines are left intact."
+ (let* ((str (copy-sequence string))
+ (pos (string-search "\n" str)))
+ (while pos
+ (if (null (get-text-property pos 'hard str))
+ (aset str pos ? ))
+ (setq pos (string-search "\n" str (1+ pos))))
+ str))
+
+;;; Auto wrap
+
+(defun longlines-auto-wrap (&optional arg)
+ "Toggle automatic line wrapping.
+With optional argument ARG, turn on line wrapping if and only if
+ARG is positive.
+If automatic line wrapping is turned on, wrap the entire buffer."
+ (interactive "P")
+ (setq arg (if arg
+ (> (prefix-numeric-value arg) 0)
+ (not longlines-auto-wrap)))
+ (if arg
+ (progn
+ (setq longlines-auto-wrap t)
+ (longlines-wrap-region (point-min) (point-max))
+ (message "Auto wrap enabled."))
+ (setq longlines-auto-wrap nil)
+ (message "Auto wrap disabled.")))
+
+(defun longlines-after-change-function (beg end _len)
+ "Update `longlines-wrap-beg' and `longlines-wrap-end'.
+This is called by `after-change-functions' to keep track of the region
+that has changed."
+ (when (and longlines-auto-wrap (not undo-in-progress))
+ (setq longlines-wrap-beg
+ (if longlines-wrap-beg (min longlines-wrap-beg beg) beg))
+ (setq longlines-wrap-end
+ (if longlines-wrap-end (max longlines-wrap-end end) end))))
+
+(defun longlines-post-command-function ()
+ "Perform line wrapping on the parts of the buffer that have changed.
+This is called by `post-command-hook' after each command."
+ (when (and longlines-auto-wrap longlines-wrap-beg)
+ (if (or (eq this-command 'yank)
+ (eq this-command 'yank-pop))
+ (longlines-decode-region (point) (mark t)))
+ (if longlines-showing
+ (longlines-show-region longlines-wrap-beg longlines-wrap-end))
+ (unless (or (eq this-command 'fill-paragraph)
+ (eq this-command 'fill-region))
+ (longlines-wrap-region longlines-wrap-beg longlines-wrap-end))
+ (setq longlines-wrap-beg nil)
+ (setq longlines-wrap-end nil)))
+
+(defun longlines-window-change-function ()
+ "Re-wrap the buffer if the window width has changed.
+This is called by `window-configuration-change-hook'."
+ (let ((dw (if (and (integerp longlines-wrap-follows-window-size)
+ (>= longlines-wrap-follows-window-size 0)
+ (< longlines-wrap-follows-window-size (window-width)))
+ longlines-wrap-follows-window-size
+ 2)))
+ (when (/= fill-column (- (window-width) dw))
+ (setq fill-column (- (window-width) dw))
+ (longlines-wrap-region (point-min) (point-max)))))
+
+;;; Isearch
+
+(defun longlines-search-function ()
+ (cond
+ ((or isearch-regexp-function isearch-regexp) (isearch-search-fun-default))
+ (isearch-forward #'longlines-search-forward)
+ (t #'longlines-search-backward)))
+
+(defun longlines-search-forward (string &optional bound noerror count)
+ (let ((search-spaces-regexp " *[ \n]"))
+ (re-search-forward (regexp-quote string) bound noerror count)))
+
+(defun longlines-search-backward (string &optional bound noerror count)
+ (let ((search-spaces-regexp " *[ \n]"))
+ (re-search-backward (regexp-quote string) bound noerror count)))
+
+(defun longlines-re-search-forward (string &optional bound noerror count)
+ (let ((search-spaces-regexp " *[ \n]"))
+ (re-search-forward string bound noerror count)))
+
+;;; Loading and saving
+
+(defun longlines-before-revert-hook ()
+ (add-hook 'after-revert-hook #'longlines-after-revert-hook nil t)
+ (longlines-mode 0))
+
+(defun longlines-after-revert-hook ()
+ (remove-hook 'after-revert-hook #'longlines-after-revert-hook t)
+ (longlines-mode 1))
+
+(add-to-list
+ 'format-alist
+ (list 'longlines "Automatically wrap long lines." nil nil
+ #'longlines-encode-region t nil))
+
+;;; Unloading
+
+(defun longlines-unload-function ()
+ "Unload the longlines library."
+ (save-current-buffer
+ (dolist (buffer (buffer-list))
+ (set-buffer buffer)
+ (longlines-mode-off)))
+ ;; continue standard unloading
+ nil)
+
+(provide 'longlines)
+
+;;; longlines.el ends here
Lisp_Object window;
struct window *w;
bool need_adjustment = 0;
+ ptrdiff_t narrowed_begv;
window = Fget_buffer_window (Fcurrent_buffer (), Qnil);
if (NILP (window))
if (NILP (string))
{
head = backlim < 0 ? BEGV : backlim, tail = ZV, stop = GPT;
+ /* In buffers with very long lines, this function becomes very
+ slow. Pretend that the buffer is narrowed to make it fast. */
+ narrowed_begv = get_narrowed_begv (w);
+ if (pos > narrowed_begv)
+ head = narrowed_begv;
cur.pos_byte = CHAR_TO_BYTE (cur.pos);
cur.p = BYTE_POS_ADDR (cur.pos_byte);
}
with which display_string was called. */
ptrdiff_t end_charpos;
+ /* Alternate begin position of the buffer, which is used to optimize
+ display (see the WITH_NARROWED_BEGV macro below). */
+ ptrdiff_t narrowed_begv;
+
/* C string to iterate over. Non-null means get characters from
this string, otherwise characters are read from current_buffer
or it->string. */
reset_box_start_end_flags ((IT)); \
} while (false)
+/* Execute STATEMENT with a temporarily narrowed buffer. */
+
+#define WITH_NARROWED_BEGV(STATEMENT) \
+ do { \
+ ptrdiff_t obegv = BEGV; \
+ if (it->narrowed_begv) \
+ SET_BUF_BEGV (current_buffer, it->narrowed_begv); \
+ STATEMENT; \
+ if (it->narrowed_begv) \
+ SET_BUF_BEGV (current_buffer, obegv); \
+ } while (0)
+
/* Bit-flags indicating what operation move_it_to should perform. */
enum move_operation_enum
void redisplay_preserve_echo_area (int);
void init_iterator (struct it *, struct window *, ptrdiff_t,
ptrdiff_t, struct glyph_row *, enum face_id);
+ptrdiff_t get_narrowed_begv (struct window *w);
void init_iterator_to_row_start (struct it *, struct window *,
struct glyph_row *);
void start_display (struct it *, struct window *, struct text_pos);
/* Return the number of lines/pixels of W's body. Don't count any mode
or header line or horizontal divider of W. Rounds down to nearest
integer when not working pixelwise. */
-static int
+int
window_body_height (struct window *w, enum window_body_unit pixelwise)
{
int height = (w->pixel_height
WINDOW_BODY_IN_REMAPPED_CHARS
};
extern int window_body_width (struct window *w, enum window_body_unit);
+extern int window_body_height (struct window *w, enum window_body_unit);
enum margin_unit { MARGIN_IN_LINES, MARGIN_IN_PIXELS };
extern int window_scroll_margin (struct window *, enum margin_unit);
extern void temp_output_buffer_show (Lisp_Object);
}
}
+ it->narrowed_begv = get_narrowed_begv (w);
+
/* If a buffer position was specified, set the iterator there,
getting overlays and face properties from that position. */
if (charpos >= BUF_BEG (current_buffer))
CHECK_IT (it);
}
+/* Compute a suitable value for BEGV that can be used temporarily, to
+ optimize display, for the buffer in window W. */
+
+ptrdiff_t
+get_narrowed_begv (struct window *w)
+{
+ int len, begv;
+ len = (1 + ((window_body_width (w, WINDOW_BODY_IN_CANONICAL_CHARS) *
+ window_body_height (w, WINDOW_BODY_IN_CANONICAL_CHARS)) /
+ 10000)) * 10000;
+ begv = max ((PT / len - 2) * len, BEGV);
+ return begv == BEGV ? 0 : begv;
+}
/* Initialize IT for the display of window W with window start POS. */
ptrdiff_t cp = IT_CHARPOS (*it), bp = IT_BYTEPOS (*it);
dec_both (&cp, &bp);
- IT_CHARPOS (*it) = find_newline_no_quit (cp, bp, -1, &IT_BYTEPOS (*it));
+ WITH_NARROWED_BEGV (IT_CHARPOS (*it) =
+ find_newline_no_quit (cp, bp, -1, &IT_BYTEPOS (*it)));
}
{
bool string_p = STRINGP (it->string) || it->s;
ptrdiff_t eob = (string_p ? it->bidi_it.string.schars : ZV);
- ptrdiff_t bob = (string_p ? 0 : BEGV);
+ ptrdiff_t bob;
+
+ WITH_NARROWED_BEGV (bob = (string_p ? 0 : BEGV));
if (STRINGP (it->string))
{
if (string_p)
it->bidi_it.charpos = it->bidi_it.bytepos = 0;
else
- it->bidi_it.charpos = find_newline_no_quit (IT_CHARPOS (*it),
- IT_BYTEPOS (*it), -1,
- &it->bidi_it.bytepos);
+ WITH_NARROWED_BEGV (it->bidi_it.charpos =
+ find_newline_no_quit (IT_CHARPOS (*it),
+ IT_BYTEPOS (*it), -1,
+ &it->bidi_it.bytepos));
bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it, true);
do
{
ptrdiff_t cp = IT_CHARPOS (*it), bp = IT_BYTEPOS (*it);
dec_both (&cp, &bp);
- cp = find_newline_no_quit (cp, bp, -1, NULL);
+ WITH_NARROWED_BEGV (cp = find_newline_no_quit (cp, bp, -1, NULL));
move_it_to (it, cp, -1, -1, -1, MOVE_TO_POS);
}
bidi_unshelve_cache (it3data, true);