I think this pretty much does what you ask, even if it has a slightly different flavor. For this you need library Isearch+ (isearch+.el
).
Select the text for that column:
a. Set the region corners before the 0
in the first line and after the 2
in the last line.
b. Use C-x SPC
, to turn on rectangle-mark-mode
.
Use C-M-s
to search for the regexp [[:digit:]]
(or whatever else you want to match in that column). Repeat C-M-s
to search forward; repeat C-M-r
to search backward.
Provided option isearchp-restrict-to-region-flag
is non-nil, which it is by default, when the region is active Isearch+ restricts searching to the region. (You can also search only outside the region.) When the region is rectangular (i.e., it satisfies region-noncontiguous-p
), search is restricted to the rectangular region.
In this case, the rectangular region is a single column of characters.
Alternatively, if you don't want to select the current column as a rectangle, you can use C-z c
during Isearch to tell it to limit searching between two columns - in this case the values of (current-column)
and (1+ (current-column))
. You are prompted for the column values, so you would first use M-: (current-column)
to get the column number.
In your case it is column 2 that you want to search, so at the prompt from C-z c
you would enter 2
and 3
for the min and max columns to search.
Or you could define your own Isearch filter-predicate-addition command for this, and bind it to a key (say C-z C
) in keymap isearchp-filter-map
:
(defun isearchp-this-column (&optional flip-read-name-p flip-read-prefix-p msgp)
"Add predicate that restricts search to this column.
You might be prompted for a predicate name or an Isearch prompt
prefix. See `isearchp-add-filter-predicate' for info about this and
about the use of a prefix argument."
(interactive
(list (and current-prefix-arg (<= (prefix-numeric-value current-prefix-arg) 0))
(and current-prefix-arg (>= (prefix-numeric-value current-prefix-arg) 0))
t))
(let ((col (current-column)))
(isearchp-add-filter-predicate
`(lambda (beg end)
(and (= (save-excursion (goto-char beg) (current-column)) ,(1- col))
(= (save-excursion (goto-char end) (current-column)) ,col)))
flip-read-name-p flip-read-prefix-p msgp)))
(define-key isearchp-filter-map (kbd "C") 'isearchp-this-column) ; `C-z C'
Or if you don't really care about adding and removing filter predicates dynamically (and you probably don't, here) then you could just define your own search command for this, using a filter predicate defined for the column where you start the search. (And then search for [[:digit]]
, as in the other cases above.)
(defun search-this-column ()
"Regexp-search current column only, using filter predicate `this-col-p'."
(interactive)
(let ((isearch-filter-predicate (this-col-p (current-column))))
(isearch-forward-regexp)))
(defun this-col-p (column)
"Return filter predicate that returns non-nil if search hit is in COLUMN."
`(lambda (beg end)
(and (= (save-excursion (goto-char beg) (current-column)) ,column)
(= (save-excursion (goto-char end) (current-column)) ,(1+ column)))))
forward-paragraph
) I'm missing, perhaps? – Arch Stanton Mar 20 '18 at 10:15