forked from purcell/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-isearch.el
40 lines (34 loc) · 1.34 KB
/
init-isearch.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
;; Use regex searching by default
(global-set-key "\C-s" 'isearch-forward-regexp)
(global-set-key "\C-r" 'isearch-backward-regexp)
(global-set-key "\C-\M-s" 'isearch-forward)
(global-set-key "\C-\M-r" 'isearch-backward)
(defun call-with-current-isearch-string-as-regex (f)
(let ((case-fold-search isearch-case-fold-search))
(funcall f (if isearch-regexp isearch-string (regexp-quote isearch-string)))))
;; Activate occur easily inside isearch
(define-key isearch-mode-map (kbd "C-o")
(lambda ()
(interactive)
(call-with-current-isearch-string-as-regex 'occur)))
;; or fire up "all"
(define-key isearch-mode-map (kbd "C-l")
(lambda ()
(interactive)
(call-with-current-isearch-string-as-regex 'all)))
;; Search back/forth for the symbol at point
;; See http://www.emacswiki.org/emacs/SearchAtPoint
(defun isearch-yank-symbol ()
"*Put symbol at current point into search string."
(interactive)
(let ((sym (symbol-at-point)))
(if sym
(progn
(setq isearch-regexp t
isearch-string (concat "\\_<" (regexp-quote (symbol-name sym)) "\\_>")
isearch-message (mapconcat 'isearch-text-char-description isearch-string "")
isearch-yank-flag t))
(ding)))
(isearch-search-and-update))
(define-key isearch-mode-map "\C-\M-w" 'isearch-yank-symbol)
(provide 'init-isearch)