Skip to content

Instantly share code, notes, and snippets.

@handlename
Created February 28, 2012 02:31
Show Gist options
  • Save handlename/1928772 to your computer and use it in GitHub Desktop.
Save handlename/1928772 to your computer and use it in GitHub Desktop.
search char sequentially
;; search char
;; http://dev.ariel-networks.com/wp/documents/aritcles/emacs/part16
;; List3
(defvar last-search-char nil)
(defvar last-search-direction 'forward)
(defun search-forward-with-char (char)
(interactive "cMove to Char: ")
(if (eq (char-after (point)) char) (forward-char))
(and (search-forward (char-to-string char) nil t)
(backward-char))
(setq last-search-char char
last-search-direction 'forward))
(defun search-backward-with-char (char)
(interactive "cMove backward to Char: ")
(search-backward (char-to-string char) nil t)
(setq last-search-char char
last-search-direction 'backward))
(defun search-repeat-with-char ()
(interactive)
(cond
((eq nil last-search-char) (message "You haven't searched yet. Stupid!"))
((eq last-search-direction 'forward)
(or (search-forward-with-char last-search-char) (backward-char)))
((eq last-search-direction 'backward) (search-backward-with-char last-search-char))))
(defun search-forward-with-char-sequential ()
(interactive)
(if (eq last-command this-command)
(search-repeat-with-char)
(search-forward-with-char (string-to-char (read-key-sequence "cMove to Char:")))))
(defun search-backward-with-char-sequential ()
(interactive)
(if (eq last-command this-command)
(search-repeat-with-char)
(search-backward-with-char (string-to-char (read-key-sequence "cMove backward to Char:")))))
(global-set-key (kbd "C--") 'search-forward-with-char-sequential)
(global-set-key (kbd "C-$") 'search-backward-with-char-sequential)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment