Function: evil-ex-z

evil-ex-z is an interactive and byte-compiled function defined in evil-commands.el.

Signature

(evil-ex-z BEG END &optional ZMARKS BANG)

Documentation

Display several lines of text surrounding the line specified by range.

BEG and END represent the range, ZMARKS represents the args in string form. With a count supplied in the args, display that number of lines. Without a count, display evil-scroll-count number of lines, or half the window height. This table explains what each mark argument does.

mark | first line | last line | new cursor line
-----+-------------------------+----------------------------+----------------
+ | current line | 1 scr (or 1 count) forward | last line
- | 1 scr (or 1 count) back | current line | last line
^ | 2 scr (or 2 count) back | 1 scr (or 1 count) back | last line
. | ½ scr (or ½ count) back | ½ scr (or ½ count) forward | last line
= | ½ scr (or ½ count) back | ½ scr (or ½ count) forward | current line

Specifying no mark at all is the same as +. If the mark is = a line of dashes is printed around the current line. If a # is included before the mark args, the lines are numbered.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-commands.el
(evil-define-command evil-ex-z (_beg end &optional zmarks _bang)
  "Display several lines of text surrounding the line specified by range.
BEG and END represent the range, ZMARKS represents the args in string form.
With a count supplied in the args, display that number of lines.  Without a
count, display `evil-scroll-count' number of lines, or half the window height.
This table explains what each mark argument does.

mark | first line              | last line                  | new cursor line
-----+-------------------------+----------------------------+----------------
+    | current line            | 1 scr (or 1 count) forward | last line
-    | 1 scr (or 1 count) back | current line               | last line
^    | 2 scr (or 2 count) back | 1 scr (or 1 count) back    | last line
.    | ½ scr (or ½ count) back | ½ scr (or ½ count) forward | last line
=    | ½ scr (or ½ count) back | ½ scr (or ½ count) forward | current line

Specifying no mark at all is the same as `+'.
If the mark is `=' a line of dashes is printed around the current line.
If a `#' is included before the mark args, the lines are numbered."
  ;; TODO implement bang argument.
  (interactive "<r><a><!>")
  (goto-char (setq end (1- end)))
  (save-match-data
    (string-match "\\(#?\\)\\([^0-9]*\\)\\([0-9]*\\)" (or zmarks ""))
    (cl-destructuring-bind (_ _ hs he ms me cs ce) (match-data)
      (let* ((linump (/= hs he))
             (mark-string (if (= ms me) "+" (substring zmarks ms me)))
             (count-string (if (= cs ce) "" (substring zmarks cs ce)))
             (count (evil--get-scroll-count (string-to-number count-string)))
             (max-mini-window-height 0.5))
        (cond
         ((< 1 (- me ms))
          (evil-beginning-of-line)
          (user-error "Too many mark args (got %d, expected 1)" (- me ms)))
         ((string= "+" mark-string)
          (ignore-errors (beginning-of-line count))
          (evil--ex-print end end count linump))
         ((string= "-" mark-string)
          (evil-beginning-of-line)
          (evil--ex-print (line-beginning-position (- 2 count)) end 1 linump))
         ((string= "^" mark-string)
          (let ((end* (progn (move-end-of-line (- 1 count)) (point)))
                (beg* (line-beginning-position (- 2 count))))
            (evil-beginning-of-line)
            (evil--ex-print beg* end* 1 linump)))
         ((string= "." mark-string)
          (let ((beg* (line-beginning-position (- 1 (floor count 2))))
                (end* (progn (move-end-of-line (ceiling count 2)) (point))))
            (evil-beginning-of-line)
            (evil--ex-print beg* end* 1 linump)))
         ((string= "=" mark-string)
          (let ((beg* (line-beginning-position (- 1 (floor count 2))))
                (end* (line-end-position (ceiling count 2))))
            (evil-beginning-of-line)
            (evil--ex-print beg* end* 1 linump (line-number-at-pos end))))
         (t (evil-beginning-of-line)
            (user-error "Invalid mark arg: %s" mark-string)))))))