comparison lisp/subword.el @ 106167:c898329ba7ba

* progmodes/cc-cmds.el (c-forward-into-nomenclature) (c-backward-into-nomenclature): Adapt to subword renaming. * subword.el (subword-forward, subword-backward, subword-mark) (subword-kill, subword-backward-kill, subword-transpose) (subword-downcase, subword-upcase, subword-capitalize) (subword-forward-internal, subword-backward-internal): Renamed from forward-subword, backward-subword, mark-subword kill-subword, backward-kill-subword, transpose-subwords, downcase-subword, upcase-subword, capitalize-subword forward-subword-internal, backward-subword-internal.
author Tassilo Horn <tassilo@member.fsf.org>
date Fri, 20 Nov 2009 18:09:29 +0000
parents b27aeda9c1fd
children
comparison
equal deleted inserted replaced
106166:858a083ed2f0 106167:c898329ba7ba
48 ;; In the minor mode, all common key bindings for word oriented 48 ;; In the minor mode, all common key bindings for word oriented
49 ;; commands are overridden by the subword oriented commands: 49 ;; commands are overridden by the subword oriented commands:
50 50
51 ;; Key Word oriented command Subword oriented command 51 ;; Key Word oriented command Subword oriented command
52 ;; ============================================================ 52 ;; ============================================================
53 ;; M-f `forward-word' `forward-subword' 53 ;; M-f `forward-word' `subword-forward'
54 ;; M-b `backward-word' `backward-subword' 54 ;; M-b `backward-word' `subword-backward'
55 ;; M-@ `mark-word' `mark-subword' 55 ;; M-@ `mark-word' `subword-mark'
56 ;; M-d `kill-word' `kill-subword' 56 ;; M-d `kill-word' `subword-kill'
57 ;; M-DEL `backward-kill-word' `backward-kill-subword' 57 ;; M-DEL `backward-kill-word' `subword-backward-kill'
58 ;; M-t `transpose-words' `transpose-subwords' 58 ;; M-t `transpose-words' `subword-transpose'
59 ;; M-c `capitalize-word' `capitalize-subword' 59 ;; M-c `capitalize-word' `subword-capitalize'
60 ;; M-u `upcase-word' `upcase-subword' 60 ;; M-u `upcase-word' `subword-upcase'
61 ;; M-l `downcase-word' `downcase-subword' 61 ;; M-l `downcase-word' `subword-downcase'
62 ;; 62 ;;
63 ;; Note: If you have changed the key bindings for the word oriented 63 ;; Note: If you have changed the key bindings for the word oriented
64 ;; commands in your .emacs or a similar place, the keys you've changed 64 ;; commands in your .emacs or a similar place, the keys you've changed
65 ;; to are also used for the corresponding subword oriented commands. 65 ;; to are also used for the corresponding subword oriented commands.
66 66
123 123
124 ;;;###autoload 124 ;;;###autoload
125 (define-global-minor-mode global-subword-mode subword-mode 125 (define-global-minor-mode global-subword-mode subword-mode
126 (lambda () (subword-mode 1))) 126 (lambda () (subword-mode 1)))
127 127
128 (defun forward-subword (&optional arg) 128 (defun subword-forward (&optional arg)
129 "Do the same as `forward-word' but on subwords. 129 "Do the same as `forward-word' but on subwords.
130 See the command `subword-mode' for a description of subwords. 130 See the command `subword-mode' for a description of subwords.
131 Optional argument ARG is the same as for `forward-word'." 131 Optional argument ARG is the same as for `forward-word'."
132 (interactive "p") 132 (interactive "p")
133 (unless arg (setq arg 1)) 133 (unless arg (setq arg 1))
134 (cond 134 (cond
135 ((< 0 arg) 135 ((< 0 arg)
136 (dotimes (i arg (point)) 136 (dotimes (i arg (point))
137 (forward-subword-internal))) 137 (subword-forward-internal)))
138 ((> 0 arg) 138 ((> 0 arg)
139 (dotimes (i (- arg) (point)) 139 (dotimes (i (- arg) (point))
140 (backward-subword-internal))) 140 (subword-backward-internal)))
141 (t 141 (t
142 (point)))) 142 (point))))
143 143
144 (put 'forward-subword 'CUA 'move) 144 (put 'subword-forward 'CUA 'move)
145 145
146 (defun backward-subword (&optional arg) 146 (defun subword-backward (&optional arg)
147 "Do the same as `backward-word' but on subwords. 147 "Do the same as `backward-word' but on subwords.
148 See the command `subword-mode' for a description of subwords. 148 See the command `subword-mode' for a description of subwords.
149 Optional argument ARG is the same as for `backward-word'." 149 Optional argument ARG is the same as for `backward-word'."
150 (interactive "p") 150 (interactive "p")
151 (forward-subword (- (or arg 1)))) 151 (subword-forward (- (or arg 1))))
152 152
153 (defun mark-subword (arg) 153 (defun subword-mark (arg)
154 "Do the same as `mark-word' but on subwords. 154 "Do the same as `mark-word' but on subwords.
155 See the command `subword-mode' for a description of subwords. 155 See the command `subword-mode' for a description of subwords.
156 Optional argument ARG is the same as for `mark-word'." 156 Optional argument ARG is the same as for `mark-word'."
157 ;; This code is almost copied from `mark-word' in GNU Emacs. 157 ;; This code is almost copied from `mark-word' in GNU Emacs.
158 (interactive "p") 158 (interactive "p")
159 (cond ((and (eq last-command this-command) (mark t)) 159 (cond ((and (eq last-command this-command) (mark t))
160 (set-mark 160 (set-mark
161 (save-excursion 161 (save-excursion
162 (goto-char (mark)) 162 (goto-char (mark))
163 (forward-subword arg) 163 (subword-forward arg)
164 (point)))) 164 (point))))
165 (t 165 (t
166 (push-mark 166 (push-mark
167 (save-excursion 167 (save-excursion
168 (forward-subword arg) 168 (subword-forward arg)
169 (point)) 169 (point))
170 nil t)))) 170 nil t))))
171 171
172 (put 'backward-subword 'CUA 'move) 172 (put 'subword-backward 'CUA 'move)
173 173
174 (defun kill-subword (arg) 174 (defun subword-kill (arg)
175 "Do the same as `kill-word' but on subwords. 175 "Do the same as `kill-word' but on subwords.
176 See the command `subword-mode' for a description of subwords. 176 See the command `subword-mode' for a description of subwords.
177 Optional argument ARG is the same as for `kill-word'." 177 Optional argument ARG is the same as for `kill-word'."
178 (interactive "p") 178 (interactive "p")
179 (kill-region (point) (forward-subword arg))) 179 (kill-region (point) (subword-forward arg)))
180 180
181 (defun backward-kill-subword (arg) 181 (defun subword-backward-kill (arg)
182 "Do the same as `backward-kill-word' but on subwords. 182 "Do the same as `backward-kill-word' but on subwords.
183 See the command `subword-mode' for a description of subwords. 183 See the command `subword-mode' for a description of subwords.
184 Optional argument ARG is the same as for `backward-kill-word'." 184 Optional argument ARG is the same as for `backward-kill-word'."
185 (interactive "p") 185 (interactive "p")
186 (kill-subword (- arg))) 186 (subword-kill (- arg)))
187 187
188 (defun transpose-subwords (arg) 188 (defun subword-transpose (arg)
189 "Do the same as `transpose-words' but on subwords. 189 "Do the same as `transpose-words' but on subwords.
190 See the command `subword-mode' for a description of subwords. 190 See the command `subword-mode' for a description of subwords.
191 Optional argument ARG is the same as for `transpose-words'." 191 Optional argument ARG is the same as for `transpose-words'."
192 (interactive "*p") 192 (interactive "*p")
193 (transpose-subr 'forward-subword arg)) 193 (transpose-subr 'subword-forward arg))
194 194
195 (defun downcase-subword (arg) 195 (defun subword-downcase (arg)
196 "Do the same as `downcase-word' but on subwords. 196 "Do the same as `downcase-word' but on subwords.
197 See the command `subword-mode' for a description of subwords. 197 See the command `subword-mode' for a description of subwords.
198 Optional argument ARG is the same as for `downcase-word'." 198 Optional argument ARG is the same as for `downcase-word'."
199 (interactive "p") 199 (interactive "p")
200 (let ((start (point))) 200 (let ((start (point)))
201 (downcase-region (point) (forward-subword arg)) 201 (downcase-region (point) (subword-forward arg))
202 (when (< arg 0) 202 (when (< arg 0)
203 (goto-char start)))) 203 (goto-char start))))
204 204
205 (defun upcase-subword (arg) 205 (defun subword-upcase (arg)
206 "Do the same as `upcase-word' but on subwords. 206 "Do the same as `upcase-word' but on subwords.
207 See the command `subword-mode' for a description of subwords. 207 See the command `subword-mode' for a description of subwords.
208 Optional argument ARG is the same as for `upcase-word'." 208 Optional argument ARG is the same as for `upcase-word'."
209 (interactive "p") 209 (interactive "p")
210 (let ((start (point))) 210 (let ((start (point)))
211 (upcase-region (point) (forward-subword arg)) 211 (upcase-region (point) (subword-forward arg))
212 (when (< arg 0) 212 (when (< arg 0)
213 (goto-char start)))) 213 (goto-char start))))
214 214
215 (defun capitalize-subword (arg) 215 (defun subword-capitalize (arg)
216 "Do the same as `capitalize-word' but on subwords. 216 "Do the same as `capitalize-word' but on subwords.
217 See the command `subword-mode' for a description of subwords. 217 See the command `subword-mode' for a description of subwords.
218 Optional argument ARG is the same as for `capitalize-word'." 218 Optional argument ARG is the same as for `capitalize-word'."
219 (interactive "p") 219 (interactive "p")
220 (let ((count (abs arg)) 220 (let ((count (abs arg))
224 (if advance 224 (if advance
225 (progn (re-search-forward 225 (progn (re-search-forward
226 (concat "[[:alpha:]]") 226 (concat "[[:alpha:]]")
227 nil t) 227 nil t)
228 (goto-char (match-beginning 0))) 228 (goto-char (match-beginning 0)))
229 (backward-subword)) 229 (subword-backward))
230 (let* ((p (point)) 230 (let* ((p (point))
231 (pp (1+ p)) 231 (pp (1+ p))
232 (np (forward-subword))) 232 (np (subword-forward)))
233 (upcase-region p pp) 233 (upcase-region p pp)
234 (downcase-region pp np) 234 (downcase-region pp np)
235 (goto-char (if advance np p)))) 235 (goto-char (if advance np p))))
236 (unless advance 236 (unless advance
237 (goto-char start)))) 237 (goto-char start))))
239 239
240 240
241 ;; 241 ;;
242 ;; Internal functions 242 ;; Internal functions
243 ;; 243 ;;
244 (defun forward-subword-internal () 244 (defun subword-forward-internal ()
245 (if (and 245 (if (and
246 (save-excursion 246 (save-excursion
247 (let ((case-fold-search nil)) 247 (let ((case-fold-search nil))
248 (re-search-forward 248 (re-search-forward
249 (concat "\\W*\\(\\([[:upper:]]*\\W?\\)[[:lower:][:digit:]]*\\)") 249 (concat "\\W*\\(\\([[:upper:]]*\\W?\\)[[:lower:][:digit:]]*\\)")
256 (t 256 (t
257 (match-end 0)))) 257 (match-end 0))))
258 (forward-word 1))) 258 (forward-word 1)))
259 259
260 260
261 (defun backward-subword-internal () 261 (defun subword-backward-internal ()
262 (if (save-excursion 262 (if (save-excursion
263 (let ((case-fold-search nil)) 263 (let ((case-fold-search nil))
264 (re-search-backward 264 (re-search-backward
265 (concat 265 (concat
266 "\\(\\(\\W\\|[[:lower:][:digit:]]\\)\\([[:upper:]]+\\W*\\)" 266 "\\(\\(\\W\\|[[:lower:][:digit:]]\\)\\([[:upper:]]+\\W*\\)"