Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Symbols as words?

10 views
Skip to first unread message

Raffaele Ricciardi

unread,
Aug 26, 2012, 10:16:42 AM8/26/12
to
Hello,

what's the option to make Emacs consider symbols as words? In Viper mode, I
used to have:

(setq viper-syntax-preference 'extended)

"`extended' means Viper word constituents are symbols that are marked as
being
parts of words OR symbols in Emacs syntax tables. This is most
appropriate for
major modes intended for editing programs."

I've looked around (Emacs Manual, Emacswiki, web forums) and I've found
nothing
besides hacking the syntax tables entry by entry.

Thanks.

Raffaele Ricciardi

unread,
Aug 26, 2012, 10:47:01 AM8/26/12
to Jude DaShiell, help-gn...@gnu.org
On 26/08/12 15:35, Jude DaShiell wrote:
> abbrev-mode might work in this case once a dictionary of abbreviations
> is built or downloaded if available.

Thank you for your help, but that is not what I'm looking for. I'm looking
for a way to make commands that work on words - e.g. `forward-word',
`backward-word', `kill-word', etc. - work on symbols instead.

Jambunathan K

unread,
Aug 26, 2012, 11:54:49 AM8/26/12
to Raffaele Ricciardi, help-gn...@gnu.org
(add-hook 'c-mode-hook
(lambda ()
(modify-syntax-entry ?_ "w")))

,---- From (info "(elisp) Syntax Class Table")
| Symbol constituents: `_'
| Extra characters used in variable and command names along with word
| constituents. Examples include the characters `$&*+-_<>' in Lisp
| mode, which may be part of a symbol name even though they are not
| part of English words. In standard C, the only
| non-word-constituent character that is valid in symbols is
| underscore (`_').
`----

>
>

--

Jude DaShiell

unread,
Aug 26, 2012, 10:35:53 AM8/26/12
to Raffaele Ricciardi, help-gn...@gnu.org
abbrev-mode might work in this case once a dictionary of abbreviations
is built or downloaded if available.
jude <jdas...@shellworld.net>


Pascal J. Bourguignon

unread,
Aug 26, 2012, 2:12:19 PM8/26/12
to
If you use forward-sexp C-M-f it skips over symbols instead of words M-f.

--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.

Raffaele Ricciardi

unread,
Aug 27, 2012, 9:57:11 AM8/27/12
to
On 26/08/12 19:12, Pascal J. Bourguignon wrote:
> If you use forward-sexp C-M-f it skips over symbols instead of words M-f.

This helps, thanks. Still, it feels weird that Emacs is oblivious to
symbols even
in Emacs Lisp code, not to mention that C-M- chords aren't super
comfortable.
So, since there is no option to customize this behaviour, I've written a
snippet
of code to do so for any programming mode. I would have preferred my
code to
scan the syntax table and convert symbol constituents to word constituents,
but I have not been able to figure out quickly the format of syntax tables,
therefore I've resorted to manually listing non-word graphic characters.

(defun rr-symbol-constituent-p (^char)
"Return non non nil if ^CHAR is a symbol constituent in the current
buffer's
syntax table."
(= (char-syntax ^char) ?_))

(defvar rr-graphic-non-word-char-list
(string-to-list "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
"List of characters besides letters and numbers that could be symbol
constituents according to syntax tables.")

(defun rr-symbols-to-words ()
"Make symbols act as words in the current buffer's syntax table."
(mapcar (lambda (^char)
(when (rr-symbol-constituent-p ^char)
(modify-syntax-entry ^char "w")))
rr-graphic-non-word-char-list))

Cheers.

Pascal J. Bourguignon

unread,
Aug 27, 2012, 10:53:45 AM8/27/12
to
Raffaele Ricciardi <rffl...@gmail.com> writes:

> On 26/08/12 19:12, Pascal J. Bourguignon wrote:
>> If you use forward-sexp C-M-f it skips over symbols instead of words M-f.
>
> This helps, thanks. Still, it feels weird that Emacs is oblivious to
> symbols even in Emacs Lisp code, not to mention that C-M- chords
> aren't super comfortable.

You can just trivially bind forward-sexp and backward-sexp to your own
confortable keys.

(global-set-key (kbd "<f5>") 'forward-sexp)
(global-set-key (kbd "<f6>") 'backward-sexp)
0 new messages