-
Notifications
You must be signed in to change notification settings - Fork 8
/
regexp-setting.el
82 lines (82 loc) · 2.81 KB
/
regexp-setting.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
;; -*- coding: utf-8 -*-
;; File: regexp-setting.el
;;
;; Author: Denny(https://www.dennyzhang.com/contact)
;;
;; Copyright 2020, https://DennyZhang.com
;; Created:2012-04-18
;; Updated: Time-stamp: <2020-02-03 15:37:42>
;; --8<-------------------------- separator ------------------------>8--
(set-default 'case-fold-search t);;Make searches case insensitive
;; --8<-------------------------- separator ------------------------>8--
(defun add-isearch-regexp-prefix (search-prefix)
"Add regexp prefix for regexp searching."
(progn
(delete search-prefix regexp-search-ring)
(setq regexp-search-ring
(add-to-list 'regexp-search-ring search-prefix))
(message "regexp search with prefix: %s" search-prefix)
))
(defun search-function ()
"Searching functions for various programming mode."
(interactive)
(let ((mode-prefix '(("Python" . "^ *def")
("Erlang" . "^[a-zA-Z]")
("C++/l" . "^[a-zA-Z]")
("Emacs-Lisp" . "^(defun ")
("Lisp" . "^(defun ")
("Shell" . "^function "))))
(add-isearch-regexp-prefix (assoc-default mode-name mode-prefix))
))
(global-set-key (kbd "C-c C-f") 'search-function)
;;(define-key python-mode-map (kbd "C-c C-f") 'search-function)
;; --8<-------------------------- separator ------------------------>8--
(global-set-key (kbd "C-c c") 'beautify-region-by-mode)
(defun beautify-region-by-mode()
(interactive)
(save-excursion
(let (cleanup-replace-rule-list)
(cond
((string-equal mode-name "Org")
(setq cleanup-replace-rule-list
'(("\n\n+\\\*" "\n*")
("," ",")
(";" ";")
("(" "(")
(")" ")")
)))
((string-equal mode-name "Ruby")
(setq cleanup-replace-rule-list
'(("\n\n+" "\n\n")
)))
(t
(setq cleanup-replace-rule-list
'(("\n\n+" "\n\n")
(" +" " ")
("," ",")
(";" ";")
("(" "(")
(")" ")")
)))
)
(clean-up-buffer-or-region cleanup-replace-rule-list)
)))
(defun beautify-web-quotation ()
(interactive)
(when (string= mode-name "Org")
(save-excursion
(save-restriction
(org-narrow-to-subtree)
(goto-char (point-min))
(while (re-search-forward "\n" nil t)
(replace-match "\n\n" nil nil))
(goto-char (point-min))
(while (re-search-forward "\n\n" nil t)
(fill-paragraph))
(goto-char (point-min))
(while (re-search-forward "\n\n" nil t)
(replace-match "\n" nil nil)))
)
))
;; --8<-------------------------- separator ------------------------>8--
;; File: regexp-setting.el ends here