comparison lisp/progmodes/cc-subword.el @ 77083:304a180098d2

(c-capitalize-subword): Implement better mimic the behavior of `capitalize-word'. They no longer move point with a negative argument. Based on code by Paul Curry.
author Masatake YAMATO <jet@gyve.org>
date Mon, 09 Apr 2007 13:01:30 +0000
parents c783ccac00cf
children c1ec1c8a8d2e
comparison
equal deleted inserted replaced
77082:c783ccac00cf 77083:304a180098d2
244 "Do the same as `capitalize-word' but on subwords. 244 "Do the same as `capitalize-word' but on subwords.
245 See the command `c-subword-mode' for a description of subwords. 245 See the command `c-subword-mode' for a description of subwords.
246 Optional argument ARG is the same as for `capitalize-word'." 246 Optional argument ARG is the same as for `capitalize-word'."
247 (interactive "p") 247 (interactive "p")
248 (let ((count (abs arg)) 248 (let ((count (abs arg))
249 (direction (if (< 0 arg) 1 -1))) 249 (start (point))
250 (advance (if (< arg 0) nil t)))
250 (dotimes (i count) 251 (dotimes (i count)
251 (when (re-search-forward 252 (if advance
252 (concat "[" c-alpha "]") 253 (progn (re-search-forward
253 nil t) 254 (concat "[" c-alpha "]")
254 (goto-char (match-beginning 0))) 255 nil t)
256 (goto-char (match-beginning 0)))
257 (c-backward-subword))
255 (let* ((p (point)) 258 (let* ((p (point))
256 (pp (1+ p)) 259 (pp (1+ p))
257 (np (c-forward-subword direction))) 260 (np (c-forward-subword)))
258 (upcase-region p pp) 261 (upcase-region p pp)
259 (downcase-region pp np) 262 (downcase-region pp np)
260 (goto-char np))))) 263 (goto-char (if advance np p))))
264 (unless advance
265 (goto-char start))))
261 266
262 267
263 268
264 ;; 269 ;;
265 ;; Internal functions 270 ;; Internal functions