[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: change "word" definition (syntax table) for double-click?
From: |
Xah Lee |
Subject: |
Re: change "word" definition (syntax table) for double-click? |
Date: |
Sun, 30 Nov 2008 21:57:55 -0800 (PST) |
User-agent: |
G2/1.0 |
On Nov 30, 9:08 pm, ead-gnu-em...@ixian.com wrote:
> Xah,
>
> ] How can I have a double-click on for instance the middle "o" in
> ] "http://www.foo.com/" highlight the entirety of "http://www.foo.com/"
> ] rather than merely the word "foo"?
>
> Thanks for your reply. I appreciate it. Unfortunately, I see that I
> sent
> you (and everyone else) down the wrong path with my poor wording. Let
> me
> try again.
>
> The double-clicking-on-a-URL was just one sample application. What I
> want is for double-clicking with the mouse to highlight, as a word,
> all
> contiguous non-whitespace characters.
>
> Some sample applications I want this for are:
>
> o Double-clicking in the middle of URLs.
> o Double-clicking in the middle of RFC822-compliant email addresses.
> o Double-clicking in the middle of passwords and other strings
> having
> non-alphanumeric characters.
>
> In short, I want the same double-clicking control inside emacs that
> character classes give me inside xterm and cutchars give me inside
> rxvt.
>
> xterm(1)
> CHARACTER CLASSES
> Clicking the left pointer button twice in rapid
> succession (double-clicking) causes all characters of
> the same class (e.g., letters, white space, punctuation)
> to be selected as a ``word''. Since different people
> have different preferences for what should be selected
> (for example, should filenames be selected as a whole or
> only the separate subnames), the default mapping can be
> overridden through the use of the charClass (class
> CharClass) resource.
>
> rxvt(1)
> cutchars: string
> The characters used as delimiters for double-click word
> selection (whitespace delimiting is added automatically
> if resource is given).
>
> Thank you for any pointers,
> Eric
That's easy.
here's a sample code:
(defun get-english-word-boundary ()
"Return the boundary of the current word.
The return value is of the form: (cons pos1 pos2).
A “word” is a sequence of letters and hyphen.
"
(save-excursion
(let (p1 p2)
(progn
(skip-chars-backward "-A-Za-z")
(setq p1 (point))
(skip-chars-forward "-A-Za-z")
(setq p2 (point)))
(cons p1 p2)
))
)
(defun select-word ()
"Mark the url under cursor."
(interactive)
; (require 'thingatpt)
(let (bds)
(setq bds (get-english-word-boundary))
(set-mark (car bds))
(goto-char (cdr bds))
)
)
you can add chars to the skip-chars-backward and skip-chars-forward so
that it'll skip to what you consider word boundary. If you want
everything except whitspace, you can use like:
(skip-chars-backward "^\n\t")
unless you are writing a mode, syntax table is probably not a good
choice here.
Xah
∑ http://xahlee.org/
☄