-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathefuncs.el
166 lines (138 loc) · 5.2 KB
/
efuncs.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
;; my personal functions and key bindings
;; unbind exit key sequence to prevernt accidental exits
(global-unset-key "\C-x\C-c")
(global-set-key "\C-x\C-g" 'goto-line)
(global-set-key "\M-4" 'ispell-word)
(global-set-key "\C-cj" 'flyspell-check-previous-highlighted-word)
(defalias 'qrr 'query-replace-regexp)
;; Insert date at this point
(defun insert-date ()
"Insert date at point."
(interactive)
(insert (format-time-string "%a %b %e, %Y %l:%M %p")))
;; edit the file Journal.txt and put a datastamp at the end
(fset 'journal
[?\C-x ?\C-f ?\C-f ?\C-a ?\C-k ?~ ?/ ?D ?o ?c tab ?p ?e ?r tab ?J ?o ?u ?r tab ?J ?o ?u ?r tab ?. tab return escape ?> return escape ?x ?i ?n ?s ?e ? ?d ? return return return ?\C-x ?\C-s])
;; (defun try-complete-abbrev (old)
;; (if (expand-abbr`ev) t nil))
;; (setq hippie-expand-try-functions-list
;; '(try-complete-abbrev
;; try-complete-file-name
;; try-expand-dabbrev))
(defun mark-buffer-and-copy ()
"Mark the entire buffer and put it in the kill ring"
(interactive)
(kill-ring-save (point-min) (point-max)))
(global-set-key "\C-xh" 'mark-buffer-and-copy)
;; count words in region (from elisp intro)
(defun count-words-region (beginning end)
"Print number of words in the region."
(interactive "r")
(message "Counting words in region ... ")
(save-excursion
(let ((count 0))
(goto-char beginning)
(while (and (< (point) end)
(re-search-forward "\\w+\\W*" end t))
(setq count (1+ count)))
(cond ((zerop count)
(message
"The region does NOT have any words."))
((= 1 count)
(message
"The region has 1 word."))
(t
(message
"The region has %d words." count))))))
;; Count the words in the entire document
(defun count-words-buffer ()
"Count all the words in the buffer"
(interactive)
(count-words-region (point-min) (point-max) )
)
;; Key mapping for counting words in buffer
(global-set-key "\C-c\C-cw" 'count-words-buffer)
;; from http://blog.tuxicity.se/elisp/emacs/2010/03/26/rename-file-and-buffer-in-emacs.html
(defun rename-file-and-buffer ()
"Renames current buffer and file it is visiting."
(interactive)
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(message "Buffer '%s' is not visiting a file!" name)
(let ((new-name (read-file-name "New name: " filename)))
(cond ((get-buffer new-name)
(message "A buffer named '%s' already exists!" new-name))
(t
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)))))))
;(global-set-key (kbd "C-c r") 'rename-file-and-buffer)
(global-set-key "\C-x\C-i" 'indent-region)
(defun unfill(beg end)
(interactive "r")
(shell-command-on-region beg end "fmt -w2000" nil t))
(defun entify-region (beginning end)
"Turn < and > into respective entities"
(interactive "r")
(save-excursion
(narrow-to-region beginning end)
(beginning-of-buffer)
(replace-string "<" "<")
(beginning-of-buffer)
(replace-string ">" ">")
(widen)
)
)
(defun copy-buffer-file-name-as-kill (choice)
"Copy the buffer-file-name to the kill-ring"
(interactive "cCopy Buffer Name (F) Full, (D) Directory, (N) Name")
(let ((new-kill-string)
(name (if (eq major-mode 'dired-mode)
(dired-get-filename)
(or (buffer-file-name) ""))))
(cond ((eq choice ?f)
(setq new-kill-string name))
((eq choice ?d)
(setq new-kill-string (file-name-directory name)))
((eq choice ?n)
(setq new-kill-string (file-name-nondirectory name)))
(t (message "Quit")))
(when new-kill-string
(message "%s copied" new-kill-string)
(kill-new new-kill-string))))
;; Shift the selected region right if distance is postive, left if
;; negative
(defun shift-region (distance)
(let ((mark (mark)))
(save-excursion
(indent-rigidly (region-beginning) (region-end) distance)
(push-mark mark t t)
;; Tell the command loop not to deactivate the mark
;; for transient mark mode
(setq deactivate-mark nil))))
(defun shift-right ()
(interactive)
(shift-region 1))
(defun shift-left ()
(interactive)
(shift-region -1))
(defun renumber-list (start end &optional num)
"Renumber the list items in the current START..END region.
If optional prefix arg NUM is given, start numbering from that number
instead of 1."
(interactive "*r\np")
(save-excursion
(goto-char start)
(setq num (or num 1))
(save-match-data
(while (re-search-forward "^[0-9]+" end t)
(replace-match (number-to-string num))
(setq num (1+ num))))))
;; Bind (shift-right) and (shift-left) function to your favorite keys. I use
;; the following so that Ctrl-Shift-Right Arrow moves selected text one
;; column to the right, Ctrl-Shift-Left Arrow moves selected text one
;; column to the left:
;;(global-set-key [C-S-right] 'shift-right)
;;(global-set-key [C-S-left] 'shift-left)