Emacs personal configuration
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

76 行
2.8KB

  1. ;; Show number of matches while searching
  2. (when (>= emacs-major-version 24)
  3. (require-package 'anzu)
  4. (global-anzu-mode t)
  5. (diminish 'anzu-mode)
  6. (global-set-key [remap query-replace-regexp] 'anzu-query-replace-regexp)
  7. (global-set-key [remap query-replace] 'anzu-query-replace))
  8. ;; Activate occur easily inside isearch
  9. (define-key isearch-mode-map (kbd "C-o") 'isearch-occur)
  10. ;; DEL during isearch should edit the search string, not jump back to the previous result
  11. (define-key isearch-mode-map [remap isearch-delete-char] 'isearch-del-char)
  12. ;; Search back/forth for the symbol at point
  13. ;; See http://www.emacswiki.org/emacs/SearchAtPoint
  14. (defun isearch-yank-symbol ()
  15. "*Put symbol at current point into search string."
  16. (interactive)
  17. (let ((sym (symbol-at-point)))
  18. (if sym
  19. (progn
  20. (setq isearch-regexp t
  21. isearch-string (concat "\\_<" (regexp-quote (symbol-name sym)) "\\_>")
  22. isearch-message (mapconcat 'isearch-text-char-description isearch-string "")
  23. isearch-yank-flag t))
  24. (ding)))
  25. (isearch-search-and-update))
  26. (define-key isearch-mode-map "\C-\M-w" 'isearch-yank-symbol)
  27. ;; http://www.emacswiki.org/emacs/ZapToISearch
  28. (defun zap-to-isearch (rbeg rend)
  29. "Kill the region between the mark and the closest portion of
  30. the isearch match string. The behaviour is meant to be analogous
  31. to zap-to-char; let's call it zap-to-isearch. The deleted region
  32. does not include the isearch word. This is meant to be bound only
  33. in isearch mode. The point of this function is that oftentimes
  34. you want to delete some portion of text, one end of which happens
  35. to be an active isearch word. The observation to make is that if
  36. you use isearch a lot to move the cursor around (as you should,
  37. it is much more efficient than using the arrows), it happens a
  38. lot that you could just delete the active region between the mark
  39. and the point, not include the isearch word."
  40. (interactive "r")
  41. (when (not mark-active)
  42. (error "Mark is not active"))
  43. (let* ((isearch-bounds (list isearch-other-end (point)))
  44. (ismin (apply 'min isearch-bounds))
  45. (ismax (apply 'max isearch-bounds))
  46. )
  47. (if (< (mark) ismin)
  48. (kill-region (mark) ismin)
  49. (if (> (mark) ismax)
  50. (kill-region ismax (mark))
  51. (error "Internal error in isearch kill function.")))
  52. (isearch-exit)
  53. ))
  54. (define-key isearch-mode-map [(meta z)] 'zap-to-isearch)
  55. ;; http://www.emacswiki.org/emacs/ZapToISearch
  56. (defun isearch-exit-other-end (rbeg rend)
  57. "Exit isearch, but at the other end of the search string.
  58. This is useful when followed by an immediate kill."
  59. (interactive "r")
  60. (isearch-exit)
  61. (goto-char isearch-other-end))
  62. (define-key isearch-mode-map [(control return)] 'isearch-exit-other-end)
  63. (provide 'init-isearch)