bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#16190: 23.4; M-x captialize-word works incorrectly


From: Kevin Rodgers
Subject: bug#16190: 23.4; M-x captialize-word works incorrectly
Date: Sat, 28 Dec 2013 12:31:16 -0700
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20

On 12/27/13 10:31 PM, Josh wrote:
On Thu, Dec 26, 2013 at 7:30 PM, Kevin Rodgers
<kevin.d.rodgers@gmail.com>  wrote:
On 12/23/13 11:59 AM, Josh wrote:

On Mon, Dec 23, 2013 at 8:12 AM, Eli Zaretskii<eliz@gnu.org>   wrote:

If you want a function that capitalizes the word at point after
looking back for its beginning, you need to code that using
thing-at-point or some such.


When point is not already at the start of the word, `capitalize-word'
can already do this pretty easily via `M-- M-c'.

(defun capitalize-word-at-point ()
   "Capitalize the word at point (i.e. around point), without moving point."
   (interactive)
   (capitalize-word -1))

Unfortunately it's not quite that simple, because calling that function
when point is before the first character of a word will capitalize the
preceding word instead of the word following point.  Something like
   (defun capitalize-word-at-point ()
     "Capitalize the word at point."
     (interactive)
     (save-excursion
       (forward-word)
       (backward-word)
       (capitalize-word 1)))
should suffice, though there are probably more elegant approaches.

How about:

(defun capitalize-word-at-point ()
  "Capitalize the word at point.
If point is within a word, don't move point."
  (interactive)
  (if (looking-at "\\b")
      (capitalize-word 1)
    (capitalize-word -1)))

Or:

(defadvice capitalize-word (before point-within-word activate)
  "When point is within a word, capitalize the word around point
-- but only when called interactively."
  (if (and (called-interactively-p 'any)
           (not (looking-at "\\b")))
      (backward-word (prefix-numeric-value current-prefix-arg))))

--
Kevin Rodgers
Denver, Colorado, USA






reply via email to

[Prev in Thread] Current Thread [Next in Thread]