viper-ex: Implement z command

* lisp/emulation/viper-ex.el (ex-token-alist):
Add 'z' command
(ex-adjust-window-point): Add var to track previous point
(ex-adjust-window-count): Add var to track previous count
(ex-adjust-window): Implement 'z' command
* etc/NEWS: Document 'z' command
This commit is contained in:
Joshua Murphy 2026-06-22 14:11:53 -04:00 committed by Eli Zaretskii
parent 7fc2bff51c
commit 8a287a3888
2 changed files with 27 additions and 1 deletions

View file

@ -334,6 +334,9 @@ Ex can now display lines unambiguously when printing using the 'list'
command. This means that certain characters such as tab will be shown
with their literal equivalents i.e. "^I".
*** New ex command: 'z'.
Ex can now print lines using the 'z' command which allows
scrolling the output of the lines.
* New Modes and Packages in Emacs 32.1

View file

@ -179,7 +179,7 @@
("open" (ex-cmd-obsolete "open"))
("list" (ex-print nil t))
("z" (ex-cmd-not-yet "z"))
("z" (ex-adjust-window))
("#" "number")
("abbreviate" (error "`%s': Vi abbreviations are obsolete. Use the more powerful Emacs abbrevs" ex-token))
@ -365,6 +365,12 @@ corresponding function symbol."
(defvar ex-cmdfile nil)
(defvar ex-cmdfile-args "")
(defvar ex-adjust-window-point 1
"Last point used for `ex-adjust-window'.")
(defvar ex-adjust-window-count 15
"Last count used for `ex-adjust-window'.")
;; flag used in viper-ex-read-file-name to indicate that we may be reading
;; multiple file names. Used for :edit and :next
(defvar viper-keep-reading-filename nil)
@ -1898,6 +1904,23 @@ The Info file for Viper does not seem to be installed.
This file is part of the standard distribution of Emacs.
Please contact your system administrator. ")))))
(defun ex-adjust-window ()
"Show and adjust the output of ex lines in a window."
(viper-default-ex-addresses)
(viper-get-ex-count)
(let ((end (car ex-addresses)) (beg (cadr ex-addresses)))
(when (> beg end) (error viper-FirstAddrExceedsSecond))
(unless ex-count (setq ex-count ex-adjust-window-count))
(let* ((emptyp (and (characterp beg)
(characterp end)))
(pos (save-excursion
(goto-char (if emptyp ex-adjust-window-point end))
(forward-line ex-count)
(pos-bol))))
(ex-print-display-lines (buffer-substring (if emptyp ex-adjust-window-point end) pos))
(setq ex-adjust-window-count ex-count
ex-adjust-window-point pos))))
;; Ex source command.
;; Loads the file specified as argument or viper-custom-file-name.
(defun ex-source ()