Function: consult-keep-lines

consult-keep-lines is an autoloaded, interactive and byte-compiled function defined in consult.el.

Signature

(consult-keep-lines FILTER &optional INITIAL)

Documentation

Filter a subset of the lines in the current buffer with live preview.

The filtered lines are kept and the other lines are deleted. When called interactively, the lines selected are those that match the minibuffer input. In order to match the inverse of the input, prefix the input with ! . When called from Elisp, the filtering is performed by a FILTER function. If the buffer is narrowed to a region, the command only acts on this region. See also consult-focus-lines which uses overlays to display only matching lines, but does not modify the buffer.

FILTER is the filter function, called for each line. INITIAL is the initial input.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/consult-20260805.1130/consult.el
;;;###autoload
(defun consult-keep-lines (filter &optional initial)
  "Filter a subset of the lines in the current buffer with live preview.

The filtered lines are kept and the other lines are deleted.  When
called interactively, the lines selected are those that match the
minibuffer input.  In order to match the inverse of the input, prefix
the input with `! '.  When called from Elisp, the filtering is performed
by a FILTER function.  If the buffer is narrowed to a region, the
command only acts on this region.  See also `consult-focus-lines' which
uses overlays to display only matching lines, but does not modify the
buffer.

FILTER is the filter function, called for each line.
INITIAL is the initial input."
  (interactive
   (list (lambda (pattern cands)
           ;; Use consult-location completion category when filtering lines
           (consult--completion-filter-dispatch
            pattern cands 'consult-location 'highlight))))
  (consult--forbid-minibuffer)
  (let ((ro buffer-read-only))
    (unwind-protect
        (minibuffer-with-setup-hook
            (lambda ()
              (when ro
                (consult--minibuffer-message
                 (substitute-command-keys
                  " [Unlocked read-only buffer. \\[minibuffer-keyboard-quit] to quit.]"))))
          (setq buffer-read-only nil)
          (consult--with-increased-gc
            (consult--prompt
             :prompt "Keep lines: "
             :initial initial
             :history 'consult--line-history
             :state (consult--keep-lines-state filter))))
      (setq buffer-read-only ro))))