* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
[not found] <E1UIiBH-0005sm-Vy@vcs.savannah.gnu.org>
@ 2013-03-21 23:44 ` Stefan Monnier
2013-03-21 23:49 ` Ted Zlatanov
0 siblings, 1 reply; 42+ messages in thread
From: Stefan Monnier @ 2013-03-21 23:44 UTC (permalink / raw)
To: Ted Zlatanov; +Cc: emacs-devel
> * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
Please don't: Give it symbol syntax instead!
Stefan
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
2013-03-21 23:44 ` [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax Stefan Monnier
@ 2013-03-21 23:49 ` Ted Zlatanov
2013-03-22 1:32 ` Stefan Monnier
0 siblings, 1 reply; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-21 23:49 UTC (permalink / raw)
To: emacs-devel
On Thu, 21 Mar 2013 19:44:22 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
SM> Please don't: Give it symbol syntax instead!
Can you explain? Sorry to be dense, but I don't know exactly what you
mean. This is specifically to make \> NOT match something that looks
like the beginning of a defun (essentially I want only "bundle x" to
match, but not "bundle_x"). But in general CFEngine uses symbol syntax
so I'd be glad to do it the right way.
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
2013-03-21 23:49 ` Ted Zlatanov
@ 2013-03-22 1:32 ` Stefan Monnier
2013-03-22 13:03 ` Ted Zlatanov
0 siblings, 1 reply; 42+ messages in thread
From: Stefan Monnier @ 2013-03-22 1:32 UTC (permalink / raw)
To: emacs-devel
> Can you explain? Sorry to be dense, but I don't know exactly what you
> mean. This is specifically to make \> NOT match something that looks
> like the beginning of a defun (essentially I want only "bundle x" to
> match, but not "bundle_x").
You want to use \_> rather than \>, then.
Stefan
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
2013-03-22 1:32 ` Stefan Monnier
@ 2013-03-22 13:03 ` Ted Zlatanov
2013-03-22 13:14 ` Tom Tromey
2013-03-22 14:13 ` [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax Stefan Monnier
0 siblings, 2 replies; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-22 13:03 UTC (permalink / raw)
To: emacs-devel
On Thu, 21 Mar 2013 21:32:31 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> Can you explain? Sorry to be dense, but I don't know exactly what you
>> mean. This is specifically to make \> NOT match something that looks
>> like the beginning of a defun (essentially I want only "bundle x" to
>> match, but not "bundle_x").
SM> You want to use \_> rather than \>, then.
OK, but what's wrong with generally declaring the _ character a word
component? In other words, what's wrong with my fix? I think I'd
rather make a base change to word syntax and use simple word motion than
change the word motion I use to symbol motion. It seems more
maintainable because CFEngine generally treats the underscore as a word
component.
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
2013-03-22 13:03 ` Ted Zlatanov
@ 2013-03-22 13:14 ` Tom Tromey
2013-03-22 13:38 ` Ted Zlatanov
2013-03-22 14:13 ` [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax Stefan Monnier
1 sibling, 1 reply; 42+ messages in thread
From: Tom Tromey @ 2013-03-22 13:14 UTC (permalink / raw)
To: emacs-devel
>>>>> "Ted" == Ted Zlatanov <tzz@lifelogs.com> writes:
Ted> OK, but what's wrong with generally declaring the _ character a word
Ted> component?
If it has word syntax then M-f and friends skip over it.
Emacs modes generally don't work this way, and it is nicer for users if
there is uniformity here.
Ted> I think I'd rather make a base change to word syntax and use simple
Ted> word motion than change the word motion I use to symbol motion.
You can still do this yourself.
Ted> It seems more maintainable because CFEngine generally treats the
Ted> underscore as a word component.
The symbol commands and syntax help here.
Tom
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
2013-03-22 13:14 ` Tom Tromey
@ 2013-03-22 13:38 ` Ted Zlatanov
2013-03-22 14:18 ` Stefan Monnier
0 siblings, 1 reply; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-22 13:38 UTC (permalink / raw)
To: emacs-devel
On Fri, 22 Mar 2013 07:14:48 -0600 Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Ted" == Ted Zlatanov <tzz@lifelogs.com> writes:
Ted> OK, but what's wrong with generally declaring the _ character a word
Ted> component?
Tom> If it has word syntax then M-f and friends skip over it.
Tom> Emacs modes generally don't work this way, and it is nicer for users if
Tom> there is uniformity here.
OK, but I can't think of any cases in CFEngine specifically where I
don't want to skip over _ with M-f. It's always part of a word. The
language itself is designed that way and has a pretty rigid syntax. Are
you saying it's still not a good idea to add _ to the word syntax? What
will it break? Or are you saying users don't expect _ to be part of a
word and it's unconventional to make it so?
Ted> I think I'd rather make a base change to word syntax and use simple
Ted> word motion than change the word motion I use to symbol motion.
Tom> You can still do this yourself.
We're talking about a change I made to cfengine.el. Obviously I can
make it for myself; the goal is to make the mode more usable. I thought
by adding _ to the word syntax I was doing that, and don't know the
reasons why it's bad, except the word motion you mentioned above.
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
2013-03-22 13:03 ` Ted Zlatanov
2013-03-22 13:14 ` Tom Tromey
@ 2013-03-22 14:13 ` Stefan Monnier
1 sibling, 0 replies; 42+ messages in thread
From: Stefan Monnier @ 2013-03-22 14:13 UTC (permalink / raw)
To: emacs-devel
> OK, but what's wrong with generally declaring the _ character a word
> component? In other words, what's wrong with my fix? I think I'd
> rather make a base change to word syntax and use simple word motion than
> change the word motion I use to symbol motion. It seems more
> maintainable because CFEngine generally treats the underscore as a word
> component.
Basically, the definition of a word is something that major modes should
not touch, because it is a notion from human language, and not from the
programming language in use in a particular buffer.
The major mode should define the syntax of symbols (aka
"identifiers") instead.
Stefan
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
2013-03-22 13:38 ` Ted Zlatanov
@ 2013-03-22 14:18 ` Stefan Monnier
2013-03-22 14:46 ` Ted Zlatanov
0 siblings, 1 reply; 42+ messages in thread
From: Stefan Monnier @ 2013-03-22 14:18 UTC (permalink / raw)
To: emacs-devel
> OK, but I can't think of any cases in CFEngine specifically where I
> don't want to skip over _ with M-f. It's always part of a word.
> The language itself is designed that way and has a pretty rigid syntax.
CFengine has no notion of words, it has a notion of identifiers, which
in Emacs are called symbols and can be skipped with C-M-f or
forward-symbol.
> Are you saying it's still not a good idea to add _ to the word syntax?
Yes.
> What will it break?
Users's expectations.
> Or are you saying users don't expect _ to be part of a
> word and it's unconventional to make it so?
Exactly. Many users actually like _ to be part of a word, but these are
user-preferences (and we should indeed define a words-are-symbols-mode
for those users since what they really want is for M-f, M-t, M-DEL to
move by symbols rather than by words).
Stefan
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
2013-03-22 14:18 ` Stefan Monnier
@ 2013-03-22 14:46 ` Ted Zlatanov
2013-03-22 17:30 ` Stefan Monnier
0 siblings, 1 reply; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-22 14:46 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1815 bytes --]
On Fri, 22 Mar 2013 10:18:37 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> OK, but I can't think of any cases in CFEngine specifically where I
>> don't want to skip over _ with M-f. It's always part of a word.
>> The language itself is designed that way and has a pretty rigid syntax.
SM> CFengine has no notion of words, it has a notion of identifiers, which
SM> in Emacs are called symbols and can be skipped with C-M-f or
SM> forward-symbol.
>> Or are you saying users don't expect _ to be part of a
>> word and it's unconventional to make it so?
SM> Exactly. Many users actually like _ to be part of a word, but these are
SM> user-preferences (and we should indeed define a words-are-symbols-mode
SM> for those users since what they really want is for M-f, M-t, M-DEL to
SM> move by symbols rather than by words).
Yes! In particular, context expressions in CFEngine are things like
"a_b_c.d_e" and it's a pain to skip over them with the usual `M-f' or
CUA keybindings. It would be nice to be able to set this as a
preference for all modes derived from `prog-mode', IIUC what you mean.
SM> Basically, the definition of a word is something that major modes should
SM> not touch, because it is a notion from human language, and not from the
SM> programming language in use in a particular buffer.
SM> The major mode should define the syntax of symbols (aka
SM> "identifiers") instead.
OK, I think I understand. You're saying "words" are not part of the
syntax for a programming language, generally, and are more of a
text-mode concept. Symbols usually are what I want if I'm parsing a
programming language.
I modified cfengine.el to use \_< and \_> for all the regular
expressions; can you take a look at the attached patch and see if it's
closer to the expected behavior?
Thanks
Ted
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: cfengine-symbol-syntax.patch --]
[-- Type: text/x-diff, Size: 6828 bytes --]
=== modified file 'lisp/progmodes/cfengine.el'
*** lisp/progmodes/cfengine.el 2013-03-21 16:11:13 +0000
--- lisp/progmodes/cfengine.el 2013-03-22 14:39:32 +0000
***************
*** 30,40 ****
;; The CFEngine 3.x support doesn't have Imenu support but patches are
;; welcome.
;; You can set it up so either `cfengine2-mode' (2.x and earlier) or
;; `cfengine3-mode' (3.x) will be picked, depending on the buffer
;; contents:
! ;; (add-to-list 'auto-mode-alist '("\\.cf\\'" . cfengine-mode))
;; OR you can choose to always use a specific version, if you prefer
;; it:
--- 30,42 ----
;; The CFEngine 3.x support doesn't have Imenu support but patches are
;; welcome.
+ ;; By default, CFEngine 3.x syntax is used.
+
;; You can set it up so either `cfengine2-mode' (2.x and earlier) or
;; `cfengine3-mode' (3.x) will be picked, depending on the buffer
;; contents:
! ;; (add-to-list 'auto-mode-alist '("\\.cf\\'" . cfengine-auto-mode))
;; OR you can choose to always use a specific version, if you prefer
;; it:
***************
*** 181,187 ****
("$(\\([[:alnum:]_]+\\))" 1 font-lock-variable-name-face)
("${\\([[:alnum:]_]+\\)}" 1 font-lock-variable-name-face)
;; Variable definitions.
! ("\\<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1 font-lock-variable-name-face)
;; File, acl &c in group: { token ... }
("{[ \t]*\\([^ \t\n]+\\)" 1 font-lock-constant-face)))
--- 183,189 ----
("$(\\([[:alnum:]_]+\\))" 1 font-lock-variable-name-face)
("${\\([[:alnum:]_]+\\)}" 1 font-lock-variable-name-face)
;; Variable definitions.
! ("\\_<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1 font-lock-variable-name-face)
;; File, acl &c in group: { token ... }
("{[ \t]*\\([^ \t\n]+\\)" 1 font-lock-constant-face)))
***************
*** 189,197 ****
`(
;; Defuns. This happens early so they don't get caught by looser
;; patterns.
! (,(concat "\\<" cfengine3-defuns-regex "\\>"
! "[ \t]+\\<\\([[:alnum:]_.:]+\\)\\>"
! "[ \t]+\\<\\([[:alnum:]_.:]+\\)"
;; Optional parentheses with variable names inside.
"\\(?:(\\([^)]*\\))\\)?")
(1 font-lock-builtin-face)
--- 191,199 ----
`(
;; Defuns. This happens early so they don't get caught by looser
;; patterns.
! (,(concat "\\_<" cfengine3-defuns-regex "\\_>"
! "[ \t]+\\_<\\([[:alnum:]_.:]+\\)\\_>"
! "[ \t]+\\_<\\([[:alnum:]_.:]+\\)"
;; Optional parentheses with variable names inside.
"\\(?:(\\([^)]*\\))\\)?")
(1 font-lock-builtin-face)
***************
*** 212,221 ****
("[@$]{\\([[:alnum:]_.:]+\\)}" 1 font-lock-variable-name-face)
;; Variable definitions.
! ("\\<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1 font-lock-variable-name-face)
;; Variable types.
! (,(concat "\\<" (eval-when-compile (regexp-opt cfengine3-vartypes t)) "\\>")
1 font-lock-type-face)))
(defvar cfengine2-imenu-expression
--- 214,223 ----
("[@$]{\\([[:alnum:]_.:]+\\)}" 1 font-lock-variable-name-face)
;; Variable definitions.
! ("\\_<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1 font-lock-variable-name-face)
;; Variable types.
! (,(concat "\\_<" (eval-when-compile (regexp-opt cfengine3-vartypes t)) "\\_>")
1 font-lock-type-face)))
(defvar cfengine2-imenu-expression
***************
*** 223,231 ****
(regexp-opt cfengine2-actions t))
":[^:]")
1)
! ("Variables/classes" "\\<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1)
! ("Variables/classes" "\\<define=\\([[:alnum:]_]+\\)" 1)
! ("Variables/classes" "\\<DefineClass\\>[ \t]+\\([[:alnum:]_]+\\)" 1))
"`imenu-generic-expression' for CFEngine mode.")
(defun cfengine2-outline-level ()
--- 225,233 ----
(regexp-opt cfengine2-actions t))
":[^:]")
1)
! ("Variables/classes" "\\_<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1)
! ("Variables/classes" "\\_<define=\\([[:alnum:]_]+\\)" 1)
! ("Variables/classes" "\\_<DefineClass\\>[ \t]+\\([[:alnum:]_]+\\)" 1))
"`imenu-generic-expression' for CFEngine mode.")
(defun cfengine2-outline-level ()
***************
*** 338,344 ****
Treats body/bundle blocks as defuns."
(unless (<= (current-column) (current-indentation))
(end-of-line))
! (if (re-search-backward (concat "^[ \t]*" cfengine3-defuns-regex "\\>") nil t)
(beginning-of-line)
(goto-char (point-min)))
t)
--- 340,346 ----
Treats body/bundle blocks as defuns."
(unless (<= (current-column) (current-indentation))
(end-of-line))
! (if (re-search-backward (concat "^[ \t]*" cfengine3-defuns-regex "\\_>") nil t)
(beginning-of-line)
(goto-char (point-min)))
t)
***************
*** 347,353 ****
"`end-of-defun' function for Cfengine 3 mode.
Treats body/bundle blocks as defuns."
(end-of-line)
! (if (re-search-forward (concat "^[ \t]*" cfengine3-defuns-regex "\\>") nil t)
(beginning-of-line)
(goto-char (point-max)))
t)
--- 349,355 ----
"`end-of-defun' function for Cfengine 3 mode.
Treats body/bundle blocks as defuns."
(end-of-line)
! (if (re-search-forward (concat "^[ \t]*" cfengine3-defuns-regex "\\_>") nil t)
(beginning-of-line)
(goto-char (point-max)))
t)
***************
*** 366,372 ****
(cond
;; Body/bundle blocks start at 0.
! ((looking-at (concat cfengine3-defuns-regex "\\>"))
(indent-line-to 0))
;; Categories are indented one step.
((looking-at (concat cfengine3-category-regex "[ \t]*\\(#.*\\)*$"))
--- 368,374 ----
(cond
;; Body/bundle blocks start at 0.
! ((looking-at (concat cfengine3-defuns-regex "\\_>"))
(indent-line-to 0))
;; Categories are indented one step.
((looking-at (concat cfengine3-category-regex "[ \t]*\\(#.*\\)*$"))
***************
*** 516,522 ****
(defun cfengine-common-syntax (table)
;; The syntax defaults seem OK to give reasonable word movement.
- (modify-syntax-entry ?w "_" table)
(modify-syntax-entry ?# "<" table)
(modify-syntax-entry ?\n ">#" table)
(modify-syntax-entry ?\" "\"" table) ; "string"
--- 518,523 ----
***************
*** 584,590 ****
(save-restriction
(goto-char (point-min))
(while (not (or (eobp) v3))
! (setq v3 (looking-at (concat cfengine3-defuns-regex "\\>")))
(forward-line)))
(if v3 (cfengine3-mode) (cfengine2-mode))))
--- 585,591 ----
(save-restriction
(goto-char (point-min))
(while (not (or (eobp) v3))
! (setq v3 (looking-at (concat cfengine3-defuns-regex "\\_>")))
(forward-line)))
(if v3 (cfengine3-mode) (cfengine2-mode))))
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
2013-03-22 14:46 ` Ted Zlatanov
@ 2013-03-22 17:30 ` Stefan Monnier
2013-03-22 19:13 ` Ted Zlatanov
0 siblings, 1 reply; 42+ messages in thread
From: Stefan Monnier @ 2013-03-22 17:30 UTC (permalink / raw)
To: emacs-devel
> Yes! In particular, context expressions in CFEngine are things like
> "a_b_c.d_e" and it's a pain to skip over them with the usual `M-f' or
> CUA keybindings.
I use C-M-f, C-M-b, C-M-t for that.
> I modified cfengine.el to use \_< and \_> for all the regular
> expressions; can you take a look at the attached patch and see if it's
> closer to the expected behavior?
That looks right, yes, thank you,
Stefan
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
2013-03-22 17:30 ` Stefan Monnier
@ 2013-03-22 19:13 ` Ted Zlatanov
2013-03-23 16:01 ` Stefan Monnier
0 siblings, 1 reply; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-22 19:13 UTC (permalink / raw)
To: emacs-devel
On Fri, 22 Mar 2013 13:30:22 -0400 Stefan Monnier <monnier@IRO.UMontreal.CA> wrote:
>> Yes! In particular, context expressions in CFEngine are things like
>> "a_b_c.d_e" and it's a pain to skip over them with the usual `M-f' or
>> CUA keybindings.
SM> I use C-M-f, C-M-b, C-M-t for that.
Right. Well, do you want me to work on the symbol-word minor mode or
will you? It seems like a pretty useful change.
>> I modified cfengine.el to use \_< and \_> for all the regular
>> expressions; can you take a look at the attached patch and see if it's
>> closer to the expected behavior?
SM> That looks right, yes, thank you,
Great, pushed. Thank you for the patient explanation.
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
2013-03-22 19:13 ` Ted Zlatanov
@ 2013-03-23 16:01 ` Stefan Monnier
2013-03-26 9:17 ` Ted Zlatanov
0 siblings, 1 reply; 42+ messages in thread
From: Stefan Monnier @ 2013-03-23 16:01 UTC (permalink / raw)
To: emacs-devel
>>> Yes! In particular, context expressions in CFEngine are things like
>>> "a_b_c.d_e" and it's a pain to skip over them with the usual `M-f' or
>>> CUA keybindings.
SM> I use C-M-f, C-M-b, C-M-t for that.
> Right. Well, do you want me to work on the symbol-word minor mode or
> will you? It seems like a pretty useful change.
I do not plan to work on it, so please go ahead. You might want to
start from subword.el which makes a similar change, tho in a different
direction (making words smaller rather than larger).
Stefan
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
2013-03-23 16:01 ` Stefan Monnier
@ 2013-03-26 9:17 ` Ted Zlatanov
2013-03-26 17:06 ` Stefan Monnier
0 siblings, 1 reply; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-26 9:17 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1258 bytes --]
On Sat, 23 Mar 2013 12:01:31 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>>>> Yes! In particular, context expressions in CFEngine are things like
>>>> "a_b_c.d_e" and it's a pain to skip over them with the usual `M-f' or
>>>> CUA keybindings.
SM> I use C-M-f, C-M-b, C-M-t for that.
>> Right. Well, do you want me to work on the symbol-word minor mode or
>> will you? It seems like a pretty useful change.
SM> I do not plan to work on it, so please go ahead. You might want to
SM> start from subword.el which makes a similar change, tho in a different
SM> direction (making words smaller rather than larger).
The below simply adds a buffer-local `subword-superiority' defcustom
which, when set, makes `subword-mode' treat symbol_words as a single
word. I named it to reflect the opposite behavior (the opposite of
"sub" is usually "super", e.g. subscript vs. superscript). Let me know
what you think and if you'd rather see a separate mode or even a
separate file instead. IMO it's such a simple change that I'd rather
not make it a big deal.
The only possible enhancement I'd want over the attached is to also make
`subword-mode' override the CUA keyboard shortcuts (C-left, C-right),
but I wasn't sure if that's OK in general.
Ted
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: subword-superiority.patch --]
[-- Type: text/x-diff, Size: 4104 bytes --]
=== modified file 'lisp/progmodes/subword.el'
--- lisp/progmodes/subword.el 2013-01-01 09:11:05 +0000
+++ lisp/progmodes/subword.el 2013-03-26 09:11:57 +0000
@@ -43,7 +43,9 @@
;; The subword oriented commands defined in this package recognize
;; subwords in a nomenclature to move between them and to edit them as
-;; words.
+;; words. You can customize `subword-superiority' to make the mode
+;; treat symbols as words instead, creating a sort of "superword-mode"
+;; (but not explicitly).
;; In the minor mode, all common key bindings for word oriented
;; commands are overridden by the subword oriented commands:
@@ -71,6 +73,13 @@
;; (lambda () (subword-mode 1)))
;;
+;; To make the mode turn `subword-superiority' on automatically for
+;; only some modes, put the following code in your .emacs:
+;;
+;; (add-hook 'c-mode-common-hook
+;; (lambda () (subword-mode 1) (setq subword-superiority t)))
+;;
+
;; Acknowledgment:
;; The regular expressions to detect subwords are mostly based on
;; the old `c-forward-into-nomenclature' originally contributed by
@@ -80,6 +89,14 @@
;;; Code:
+(defcustom subword-superiority nil
+ "Whether `subword-mode' should move inside SubWords or treat symbols as words.
+Becomes buffer-local when set."
+ :group 'editing
+ :type '(choice (const :tag "Treat SubWords as two words" nil)
+ (const :tag "Treat symbol_words as a single word" t)))
+(make-variable-buffer-local 'subword-superiority)
+
(defvar subword-forward-function 'subword-forward-internal
"Function to call for forward subword movement.")
@@ -128,6 +145,9 @@
EmacsFrameClass => \"Emacs\", \"Frame\" and \"Class\"
NSGraphicsContext => \"NS\", \"Graphics\" and \"Context\"
+When `subword-superiority' is set to t, `subword-mode' treats
+symbol_words as single words instead.
+
The subword oriented commands activated in this minor mode recognize
subwords in a nomenclature to move between subwords and to edit them
as words.
@@ -143,6 +163,9 @@
(define-global-minor-mode global-subword-mode subword-mode
(lambda () (subword-mode 1)))
+(define-global-minor-mode global-superword-mode subword-mode
+ (lambda () (subword-mode 1) (setq subword-superiority t)))
+
(defun subword-forward (&optional arg)
"Do the same as `forward-word' but on subwords.
See the command `subword-mode' for a description of subwords.
@@ -260,33 +283,37 @@
;; Internal functions
;;
(defun subword-forward-internal ()
- (if (and
- (save-excursion
- (let ((case-fold-search nil))
- (re-search-forward subword-forward-regexp nil t)))
- (> (match-end 0) (point)))
- (goto-char
- (cond
- ((< 1 (- (match-end 2) (match-beginning 2)))
- (1- (match-end 2)))
- (t
- (match-end 0))))
- (forward-word 1)))
+ (if subword-superiority
+ (forward-symbol 1)
+ (if (and
+ (save-excursion
+ (let ((case-fold-search nil))
+ (re-search-forward subword-forward-regexp nil t)))
+ (> (match-end 0) (point)))
+ (goto-char
+ (cond
+ ((< 1 (- (match-end 2) (match-beginning 2)))
+ (1- (match-end 2)))
+ (t
+ (match-end 0))))
+ (forward-word 1))))
(defun subword-backward-internal ()
- (if (save-excursion
- (let ((case-fold-search nil))
- (re-search-backward subword-backward-regexp nil t)))
- (goto-char
- (cond
- ((and (match-end 3)
- (< 1 (- (match-end 3) (match-beginning 3)))
- (not (eq (point) (match-end 3))))
- (1- (match-end 3)))
- (t
- (1+ (match-beginning 0)))))
- (backward-word 1)))
+ (if subword-superiority
+ (forward-symbol -1)
+ (if (save-excursion
+ (let ((case-fold-search nil))
+ (re-search-backward subword-backward-regexp nil t)))
+ (goto-char
+ (cond
+ ((and (match-end 3)
+ (< 1 (- (match-end 3) (match-beginning 3)))
+ (not (eq (point) (match-end 3))))
+ (1- (match-end 3)))
+ (t
+ (1+ (match-beginning 0)))))
+ (backward-word 1))))
\f
(provide 'subword)
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
2013-03-26 9:17 ` Ted Zlatanov
@ 2013-03-26 17:06 ` Stefan Monnier
2013-03-26 19:04 ` superword-mode (was: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.) Ted Zlatanov
0 siblings, 1 reply; 42+ messages in thread
From: Stefan Monnier @ 2013-03-26 17:06 UTC (permalink / raw)
To: emacs-devel
> The below simply adds a buffer-local `subword-superiority' defcustom
> which, when set, makes `subword-mode' treat symbol_words as a single
> word. I named it to reflect the opposite behavior (the opposite of
> "sub" is usually "super", e.g. subscript vs. superscript). Let me know
> what you think and if you'd rather see a separate mode or even a
> separate file instead. IMO it's such a simple change that I'd rather
> not make it a big deal.
Using the same file sounds good (if we can come up with a good
encompassing name, we could rename it, but for now it can stay as it is).
So it mostly looks OK, except that rather than a defcustom, I'd prefer
to have a new superword-mode minor mode (and global-superword-mode,
which you already added).
> The only possible enhancement I'd want over the attached is to also make
> `subword-mode' override the CUA keyboard shortcuts (C-left, C-right),
> but I wasn't sure if that's OK in general.
Yes, that'd be good.
Stefan
^ permalink raw reply [flat|nested] 42+ messages in thread
* superword-mode (was: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.)
2013-03-26 17:06 ` Stefan Monnier
@ 2013-03-26 19:04 ` Ted Zlatanov
2013-03-27 1:23 ` superword-mode Stefan Monnier
` (2 more replies)
0 siblings, 3 replies; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-26 19:04 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1746 bytes --]
On Tue, 26 Mar 2013 13:06:48 -0400 Stefan Monnier <monnier@IRO.UMontreal.CA> wrote:
>> The below simply adds a buffer-local `subword-superiority' defcustom
>> which, when set, makes `subword-mode' treat symbol_words as a single
>> word. I named it to reflect the opposite behavior (the opposite of
>> "sub" is usually "super", e.g. subscript vs. superscript). Let me know
>> what you think and if you'd rather see a separate mode or even a
>> separate file instead. IMO it's such a simple change that I'd rather
>> not make it a big deal.
SM> Using the same file sounds good (if we can come up with a good
SM> encompassing name, we could rename it, but for now it can stay as it is).
SM> So it mostly looks OK, except that rather than a defcustom, I'd prefer
SM> to have a new superword-mode minor mode (and global-superword-mode,
SM> which you already added).
OK; see attached. Implemented by looking at the `superword-mode'
variable in the internal `subword-mode' commands.
Note new lighter for `subword-mode' as well. I tried to make the two
modes mutually exclusive but perhaps there's a better way than
explicitly doing it?
Right now, if I do
M-x subword-mode
M-x superword-mode
It correctly turns off `subword-mode' but does not turn `superword-mode'
on. I have to do `M-x superword-mode' again to enable
`superword-mode'. I'm not sure how the minor modes interact and didn't
want to spend too much time on the mutual exclusivity.
>> The only possible enhancement I'd want over the attached is to also make
>> `subword-mode' override the CUA keyboard shortcuts (C-left, C-right),
>> but I wasn't sure if that's OK in general.
SM> Yes, that'd be good.
Included and done for both `subword-mode' and `superword-mode'.
Ted
[-- Attachment #2: superword-mode.patch --]
[-- Type: text/x-diff, Size: 6579 bytes --]
=== modified file 'lisp/progmodes/subword.el'
--- lisp/progmodes/subword.el 2013-01-01 09:11:05 +0000
+++ lisp/progmodes/subword.el 2013-03-26 18:57:53 +0000
@@ -26,7 +26,8 @@
;; This package provides `subword' oriented commands and a minor mode
;; (`subword-mode') that substitutes the common word handling
-;; functions with them.
+;; functions with them. It also provides the `superword-mode' minor
+;; mode that treats symbols as words, the opposite of `subword-mode'.
;; In spite of GNU Coding Standards, it is popular to name a symbol by
;; mixing uppercase and lowercase letters, e.g. "GtkWidget",
@@ -43,12 +44,13 @@
;; The subword oriented commands defined in this package recognize
;; subwords in a nomenclature to move between them and to edit them as
-;; words.
+;; words. You also get a mode to treat symbols as words instead,
+;; called `superword-mode' (the opposite of `subword-mode').
;; In the minor mode, all common key bindings for word oriented
;; commands are overridden by the subword oriented commands:
-;; Key Word oriented command Subword oriented command
+;; Key Word oriented command Subword oriented command (also superword)
;; ============================================================
;; M-f `forward-word' `subword-forward'
;; M-b `backward-word' `subword-backward'
@@ -71,6 +73,13 @@
;; (lambda () (subword-mode 1)))
;;
+;; To make the mode turn `superword-mode' on automatically for
+;; only some modes, put the following code in your .emacs:
+;;
+;; (add-hook 'c-mode-common-hook
+;; (lambda () (superword-mode 1)))
+;;
+
;; Acknowledgment:
;; The regular expressions to detect subwords are mostly based on
;; the old `c-forward-into-nomenclature' originally contributed by
@@ -98,7 +107,8 @@
(let ((map (make-sparse-keymap)))
(dolist (cmd '(forward-word backward-word mark-word kill-word
backward-kill-word transpose-words
- capitalize-word upcase-word downcase-word))
+ capitalize-word upcase-word downcase-word
+ left-word right-word))
(let ((othercmd (let ((name (symbol-name cmd)))
(string-match "\\([[:alpha:]-]+\\)-word[s]?" name)
(intern (concat "subword-" (match-string 1 name))))))
@@ -133,9 +143,11 @@
as words.
\\{subword-mode-map}"
- nil
- nil
- subword-mode-map)
+ :lighter " ,"
+ nil
+ nil
+ subword-mode-map
+ (when superword-mode (superword-mode -1)))
(define-obsolete-function-alias 'c-subword-mode 'subword-mode "23.2")
@@ -161,6 +173,10 @@
(put 'subword-forward 'CUA 'move)
+(defun subword-right (&optional arg)
+ (interactive "p")
+ (subword-forward arg))
+
(defun subword-backward (&optional arg)
"Do the same as `backward-word' but on subwords.
See the command `subword-mode' for a description of subwords.
@@ -168,6 +184,10 @@
(interactive "p")
(subword-forward (- (or arg 1))))
+(defun subword-left (&optional arg)
+ (interactive "p")
+ (subword-backward arg))
+
(defun subword-mark (arg)
"Do the same as `mark-word' but on subwords.
See the command `subword-mode' for a description of subwords.
@@ -254,41 +274,86 @@
(unless advance
(goto-char start))))
+\f
+
+(defvar superword-mode-map
+ (let ((map (make-sparse-keymap)))
+ (dolist (cmd '(forward-word backward-word mark-word kill-word
+ backward-kill-word transpose-words
+ capitalize-word upcase-word downcase-word
+ left-word right-word))
+ (let ((othercmd (let ((name (symbol-name cmd)))
+ (string-match "\\([[:alpha:]-]+\\)-word[s]?" name)
+ (intern (concat "subword-" (match-string 1 name))))))
+ (define-key map (vector 'remap cmd) othercmd)))
+ map)
+ "Keymap used in `superword-mode' minor mode.")
+
+;;;###autoload
+(define-minor-mode superword-mode
+ "Toggle superword movement and editing (Superword mode).
+With a prefix argument ARG, enable Superword mode if ARG is
+positive, and disable it otherwise. If called from Lisp, enable
+the mode if ARG is omitted or nil.
+
+Superword mode is a buffer-local minor mode. Enabling it remaps
+word-based editing commands to superword-based commands that
+treat symbols as words, e.g. \"this_is_a_symbol\".
+
+The superword oriented commands activated in this minor mode
+recognize symbols as superwords to move between superwords and to
+edit them as words.
+
+\\{superword-mode-map}"
+ :lighter " ¹"
+ nil
+ nil
+ superword-mode-map
+ (when subword-mode (subword-mode -1)))
+
+;;;###autoload
+(define-global-minor-mode global-superword-mode superword-mode
+ (lambda () (superword-mode 1)))
\f
;;
;; Internal functions
;;
(defun subword-forward-internal ()
- (if (and
- (save-excursion
- (let ((case-fold-search nil))
- (re-search-forward subword-forward-regexp nil t)))
- (> (match-end 0) (point)))
- (goto-char
- (cond
- ((< 1 (- (match-end 2) (match-beginning 2)))
- (1- (match-end 2)))
- (t
- (match-end 0))))
- (forward-word 1)))
-
+ (if superword-mode
+ (forward-symbol 1)
+ (if (and
+ (save-excursion
+ (let ((case-fold-search nil))
+ (re-search-forward subword-forward-regexp nil t)))
+ (> (match-end 0) (point)))
+ (goto-char
+ (cond
+ ((< 1 (- (match-end 2) (match-beginning 2)))
+ (1- (match-end 2)))
+ (t
+ (match-end 0))))
+ (forward-word 1))))
(defun subword-backward-internal ()
- (if (save-excursion
- (let ((case-fold-search nil))
- (re-search-backward subword-backward-regexp nil t)))
- (goto-char
- (cond
- ((and (match-end 3)
- (< 1 (- (match-end 3) (match-beginning 3)))
- (not (eq (point) (match-end 3))))
- (1- (match-end 3)))
- (t
- (1+ (match-beginning 0)))))
- (backward-word 1)))
+ (if superword-mode
+ (forward-symbol -1)
+ (if (save-excursion
+ (let ((case-fold-search nil))
+ (re-search-backward subword-backward-regexp nil t)))
+ (goto-char
+ (cond
+ ((and (match-end 3)
+ (< 1 (- (match-end 3) (match-beginning 3)))
+ (not (eq (point) (match-end 3))))
+ (1- (match-end 3)))
+ (t
+ (1+ (match-beginning 0)))))
+ (backward-word 1))))
\f
+
(provide 'subword)
+(provide 'superword)
;;; subword.el ends here
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-26 19:04 ` superword-mode (was: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.) Ted Zlatanov
@ 2013-03-27 1:23 ` Stefan Monnier
2013-03-27 3:18 ` superword-mode Masatake YAMATO
2013-03-27 13:04 ` superword-mode Ted Zlatanov
2013-03-27 15:03 ` superword-mode Davis Herring
2013-03-28 23:00 ` superword-mode Ted Zlatanov
2 siblings, 2 replies; 42+ messages in thread
From: Stefan Monnier @ 2013-03-27 1:23 UTC (permalink / raw)
To: emacs-devel
> OK; see attached. Implemented by looking at the `superword-mode'
> variable in the internal `subword-mode' commands.
Looks good, see comments below.
> Included and done for both `subword-mode' and `superword-mode'.
BTW, this needs an entry in etc/NEWS, of course.
> +;; (add-hook 'c-mode-common-hook
> +;; (lambda () (superword-mode 1)))
This should be simply
+;; (add-hook 'c-mode-common-hook 'superword-mode)
> + :lighter " ,"
> + nil
> + nil
> + subword-mode-map
The "three args" are only used if there's no :keyword arg.
So the above is the same as
> + :lighter " ,"
> + (progn nil
> + nil
> + subword-mode-map)
The subword-mode-map should be used by default anyway, so you can just
remove those 3 expressions.
I'm not sure we want to add a :lighter, by the way.
> +(defun subword-right (&optional arg)
> + (interactive "p")
> + (subword-forward arg))
Why not (defalias 'subword-right 'subword-forward)?
Else, please add a docstring.
> +(defun subword-left (&optional arg)
> + (interactive "p")
> + (subword-backward arg))
Same here.
> +(defvar superword-mode-map
> + (let ((map (make-sparse-keymap)))
> + (dolist (cmd '(forward-word backward-word mark-word kill-word
> + backward-kill-word transpose-words
> + capitalize-word upcase-word downcase-word
> + left-word right-word))
> + (let ((othercmd (let ((name (symbol-name cmd)))
> + (string-match "\\([[:alpha:]-]+\\)-word[s]?" name)
> + (intern (concat "subword-" (match-string 1 name))))))
> + (define-key map (vector 'remap cmd) othercmd)))
> + map)
Why not (defvar superword-mode-map subword-mode-map)?
Stefan
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-27 1:23 ` superword-mode Stefan Monnier
@ 2013-03-27 3:18 ` Masatake YAMATO
2013-03-27 9:31 ` superword-mode Andreas Schwab
` (2 more replies)
2013-03-27 13:04 ` superword-mode Ted Zlatanov
1 sibling, 3 replies; 42+ messages in thread
From: Masatake YAMATO @ 2013-03-27 3:18 UTC (permalink / raw)
To: monnier; +Cc: emacs-devel
>> +(defvar superword-mode-map
>> + (let ((map (make-sparse-keymap)))
>> + (dolist (cmd '(forward-word backward-word mark-word kill-word
>> + backward-kill-word transpose-words
>> + capitalize-word upcase-word downcase-word
>> + left-word right-word))
>> + (let ((othercmd (let ((name (symbol-name cmd)))
>> + (string-match "\\([[:alpha:]-]+\\)-word[s]?" name)
>> + (intern (concat "subword-" (match-string 1 name))))))
>> + (define-key map (vector 'remap cmd) othercmd)))
>> + map)
>
> Why not (defvar superword-mode-map subword-mode-map)?
How about using copy-keymap to handle the case an user wants to
modify the keymaps separately?
Masatake YAMATO
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-27 3:18 ` superword-mode Masatake YAMATO
@ 2013-03-27 9:31 ` Andreas Schwab
2013-03-27 13:06 ` superword-mode Ted Zlatanov
2013-03-27 13:14 ` superword-mode Stefan Monnier
2 siblings, 0 replies; 42+ messages in thread
From: Andreas Schwab @ 2013-03-27 9:31 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: monnier, emacs-devel
Masatake YAMATO <yamato@redhat.com> writes:
>>> +(defvar superword-mode-map
>>> + (let ((map (make-sparse-keymap)))
>>> + (dolist (cmd '(forward-word backward-word mark-word kill-word
>>> + backward-kill-word transpose-words
>>> + capitalize-word upcase-word downcase-word
>>> + left-word right-word))
>>> + (let ((othercmd (let ((name (symbol-name cmd)))
>>> + (string-match "\\([[:alpha:]-]+\\)-word[s]?" name)
>>> + (intern (concat "subword-" (match-string 1 name))))))
>>> + (define-key map (vector 'remap cmd) othercmd)))
>>> + map)
>>
>> Why not (defvar superword-mode-map subword-mode-map)?
>
> How about using copy-keymap to handle the case an user wants to
> modify the keymaps separately?
Maybe inherit one from the other.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-27 1:23 ` superword-mode Stefan Monnier
2013-03-27 3:18 ` superword-mode Masatake YAMATO
@ 2013-03-27 13:04 ` Ted Zlatanov
2013-03-27 13:50 ` superword-mode Stefan Monnier
1 sibling, 1 reply; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-27 13:04 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 2256 bytes --]
On Tue, 26 Mar 2013 21:23:18 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> OK; see attached. Implemented by looking at the `superword-mode'
>> variable in the internal `subword-mode' commands.
SM> Looks good, see comments below.
>> Included and done for both `subword-mode' and `superword-mode'.
SM> BTW, this needs an entry in etc/NEWS, of course.
OK; done.
>> +;; (add-hook 'c-mode-common-hook
>> +;; (lambda () (superword-mode 1)))
SM> This should be simply
SM> +;; (add-hook 'c-mode-common-hook 'superword-mode)
OK; done for both cases in the docs.
>> + :lighter " ,"
>> + nil
>> + nil
>> + subword-mode-map
SM> The "three args" are only used if there's no :keyword arg.
SM> So the above is the same as
>> + :lighter " ,"
>> + (progn nil
>> + nil
>> + subword-mode-map)
SM> The subword-mode-map should be used by default anyway, so you can just
SM> remove those 3 expressions.
Oh, OK. Done for both subword and superword.
SM> I'm not sure we want to add a :lighter, by the way.
Booo. I want my modeline to look like a Christmas tree ;)
SM> Why not (defalias 'subword-right 'subword-forward)?
SM> Else, please add a docstring.
I thought it would be nicer, but I see it's not. Changed for both left
and right.
>> +(defvar superword-mode-map
>> + (let ((map (make-sparse-keymap)))
>> + (dolist (cmd '(forward-word backward-word mark-word kill-word
>> + backward-kill-word transpose-words
>> + capitalize-word upcase-word downcase-word
>> + left-word right-word))
>> + (let ((othercmd (let ((name (symbol-name cmd)))
>> + (string-match "\\([[:alpha:]-]+\\)-word[s]?" name)
>> + (intern (concat "subword-" (match-string 1 name))))))
>> + (define-key map (vector 'remap cmd) othercmd)))
>> + map)
SM> Why not (defvar superword-mode-map subword-mode-map)?
OK; done. I'd rather not inherit, they are identical right now.
I still don't have the mutual exclusivity working; you can't go
subword->superword with `M-x superword-mode'. It goes
subword->subword disabled->superword and you have to do
`M-x superword-mode' twice. See attached.
Ted
[-- Attachment #2: superword-mode2.patch --]
[-- Type: text/x-diff, Size: 6653 bytes --]
=== modified file 'etc/NEWS'
--- etc/NEWS 2013-03-23 00:38:11 +0000
+++ etc/NEWS 2013-03-27 12:55:03 +0000
@@ -254,6 +254,11 @@
\f
* New Modes and Packages in Emacs 24.4
+** New `superword-mode' in subword.el
+`superword-mode' overrides the default word motion commands to treat
+symbol_words as a single word, similar to what `subword-mode' does and
+using the same internal functions.
+
** New nadvice.el package offering lighter-weight advice facilities.
It is layered as:
- add-function/remove-function which can be used to add/remove code on any
=== modified file 'lisp/progmodes/subword.el'
--- lisp/progmodes/subword.el 2013-01-01 09:11:05 +0000
+++ lisp/progmodes/subword.el 2013-03-27 13:01:32 +0000
@@ -26,7 +26,8 @@
;; This package provides `subword' oriented commands and a minor mode
;; (`subword-mode') that substitutes the common word handling
-;; functions with them.
+;; functions with them. It also provides the `superword-mode' minor
+;; mode that treats symbols as words, the opposite of `subword-mode'.
;; In spite of GNU Coding Standards, it is popular to name a symbol by
;; mixing uppercase and lowercase letters, e.g. "GtkWidget",
@@ -43,12 +44,13 @@
;; The subword oriented commands defined in this package recognize
;; subwords in a nomenclature to move between them and to edit them as
-;; words.
+;; words. You also get a mode to treat symbols as words instead,
+;; called `superword-mode' (the opposite of `subword-mode').
;; In the minor mode, all common key bindings for word oriented
;; commands are overridden by the subword oriented commands:
-;; Key Word oriented command Subword oriented command
+;; Key Word oriented command Subword oriented command (also superword)
;; ============================================================
;; M-f `forward-word' `subword-forward'
;; M-b `backward-word' `subword-backward'
@@ -67,8 +69,13 @@
;; To make the mode turn on automatically, put the following code in
;; your .emacs:
;;
-;; (add-hook 'c-mode-common-hook
-;; (lambda () (subword-mode 1)))
+;; (add-hook 'c-mode-common-hook 'subword-mode)
+;;
+
+;; To make the mode turn `superword-mode' on automatically for
+;; only some modes, put the following code in your .emacs:
+;;
+;; (add-hook 'c-mode-common-hook 'superword-mode)
;;
;; Acknowledgment:
@@ -98,7 +105,8 @@
(let ((map (make-sparse-keymap)))
(dolist (cmd '(forward-word backward-word mark-word kill-word
backward-kill-word transpose-words
- capitalize-word upcase-word downcase-word))
+ capitalize-word upcase-word downcase-word
+ left-word right-word))
(let ((othercmd (let ((name (symbol-name cmd)))
(string-match "\\([[:alpha:]-]+\\)-word[s]?" name)
(intern (concat "subword-" (match-string 1 name))))))
@@ -133,9 +141,8 @@
as words.
\\{subword-mode-map}"
- nil
- nil
- subword-mode-map)
+ :lighter " ,"
+ (when superword-mode (superword-mode -1)))
(define-obsolete-function-alias 'c-subword-mode 'subword-mode "23.2")
@@ -161,6 +168,8 @@
(put 'subword-forward 'CUA 'move)
+(defalias 'subword-right 'subword-forward)
+
(defun subword-backward (&optional arg)
"Do the same as `backward-word' but on subwords.
See the command `subword-mode' for a description of subwords.
@@ -168,6 +177,8 @@
(interactive "p")
(subword-forward (- (or arg 1))))
+(defalias 'subword-left 'subword-backward)
+
(defun subword-mark (arg)
"Do the same as `mark-word' but on subwords.
See the command `subword-mode' for a description of subwords.
@@ -254,41 +265,73 @@
(unless advance
(goto-char start))))
+\f
+
+(defvar superword-mode-map subword-mode-map
+ "Keymap used in `superword-mode' minor mode.")
+
+;;;###autoload
+(define-minor-mode superword-mode
+ "Toggle superword movement and editing (Superword mode).
+With a prefix argument ARG, enable Superword mode if ARG is
+positive, and disable it otherwise. If called from Lisp, enable
+the mode if ARG is omitted or nil.
+
+Superword mode is a buffer-local minor mode. Enabling it remaps
+word-based editing commands to superword-based commands that
+treat symbols as words, e.g. \"this_is_a_symbol\".
+
+The superword oriented commands activated in this minor mode
+recognize symbols as superwords to move between superwords and to
+edit them as words.
+
+\\{superword-mode-map}"
+ :lighter " ²"
+ (when subword-mode (subword-mode -1)))
+
+;;;###autoload
+(define-global-minor-mode global-superword-mode superword-mode
+ (lambda () (superword-mode 1)))
\f
;;
;; Internal functions
;;
(defun subword-forward-internal ()
- (if (and
- (save-excursion
- (let ((case-fold-search nil))
- (re-search-forward subword-forward-regexp nil t)))
- (> (match-end 0) (point)))
- (goto-char
- (cond
- ((< 1 (- (match-end 2) (match-beginning 2)))
- (1- (match-end 2)))
- (t
- (match-end 0))))
- (forward-word 1)))
-
+ (if superword-mode
+ (forward-symbol 1)
+ (if (and
+ (save-excursion
+ (let ((case-fold-search nil))
+ (re-search-forward subword-forward-regexp nil t)))
+ (> (match-end 0) (point)))
+ (goto-char
+ (cond
+ ((< 1 (- (match-end 2) (match-beginning 2)))
+ (1- (match-end 2)))
+ (t
+ (match-end 0))))
+ (forward-word 1))))
(defun subword-backward-internal ()
- (if (save-excursion
- (let ((case-fold-search nil))
- (re-search-backward subword-backward-regexp nil t)))
- (goto-char
- (cond
- ((and (match-end 3)
- (< 1 (- (match-end 3) (match-beginning 3)))
- (not (eq (point) (match-end 3))))
- (1- (match-end 3)))
- (t
- (1+ (match-beginning 0)))))
- (backward-word 1)))
+ (if superword-mode
+ (forward-symbol -1)
+ (if (save-excursion
+ (let ((case-fold-search nil))
+ (re-search-backward subword-backward-regexp nil t)))
+ (goto-char
+ (cond
+ ((and (match-end 3)
+ (< 1 (- (match-end 3) (match-beginning 3)))
+ (not (eq (point) (match-end 3))))
+ (1- (match-end 3)))
+ (t
+ (1+ (match-beginning 0)))))
+ (backward-word 1))))
\f
+
(provide 'subword)
+(provide 'superword)
;;; subword.el ends here
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-27 3:18 ` superword-mode Masatake YAMATO
2013-03-27 9:31 ` superword-mode Andreas Schwab
@ 2013-03-27 13:06 ` Ted Zlatanov
2013-03-27 13:14 ` superword-mode Stefan Monnier
2 siblings, 0 replies; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-27 13:06 UTC (permalink / raw)
To: emacs-devel
On Wed, 27 Mar 2013 12:18:29 +0900 (JST) Masatake YAMATO <yamato@redhat.com> wrote:
>>> +(defvar superword-mode-map
>>> + (let ((map (make-sparse-keymap)))
>>> + (dolist (cmd '(forward-word backward-word mark-word kill-word
>>> + backward-kill-word transpose-words
>>> + capitalize-word upcase-word downcase-word
>>> + left-word right-word))
>>> + (let ((othercmd (let ((name (symbol-name cmd)))
>>> + (string-match "\\([[:alpha:]-]+\\)-word[s]?" name)
>>> + (intern (concat "subword-" (match-string 1 name))))))
>>> + (define-key map (vector 'remap cmd) othercmd)))
>>> + map)
>>
>> Why not (defvar superword-mode-map subword-mode-map)?
MY> How about using copy-keymap to handle the case an user wants to
MY> modify the keymaps separately?
Currently they are the same function internally so I didn't think it's
likely the user will need to modify just one of the two keymaps. If you
still disagree, I'll make the change. I don't know the subtleties of
keymaps well, so your advice is appreciated.
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-27 3:18 ` superword-mode Masatake YAMATO
2013-03-27 9:31 ` superword-mode Andreas Schwab
2013-03-27 13:06 ` superword-mode Ted Zlatanov
@ 2013-03-27 13:14 ` Stefan Monnier
2 siblings, 0 replies; 42+ messages in thread
From: Stefan Monnier @ 2013-03-27 13:14 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: emacs-devel
> How about using copy-keymap to handle the case an user wants to
> modify the keymaps separately?
I hate copy-keymap. If you really want, then move the keymap to
subword-mode-shared-map and then have subword-mode-map and
superword-mode-map both inherit from subword-mode-shared-map, but
I suspect your hypothetical user doesn't exist.
Stefan
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-27 13:04 ` superword-mode Ted Zlatanov
@ 2013-03-27 13:50 ` Stefan Monnier
2013-03-27 14:06 ` superword-mode Ted Zlatanov
0 siblings, 1 reply; 42+ messages in thread
From: Stefan Monnier @ 2013-03-27 13:50 UTC (permalink / raw)
To: emacs-devel
> I still don't have the mutual exclusivity working; you can't go
> subword-superword with `M-x superword-mode'. It goes
> subword-subword disabled->superword and you have to do
> `M-x superword-mode' twice. See attached.
Feel free to install, thank you.
> + (when superword-mode (superword-mode -1)))
This should be (when subword-mode (superword-mode -1))
> + (when subword-mode (subword-mode -1)))
And this should be (when superword-mode (subword-mode -1))
Stefan
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-27 13:50 ` superword-mode Stefan Monnier
@ 2013-03-27 14:06 ` Ted Zlatanov
0 siblings, 0 replies; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-27 14:06 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
On Wed, 27 Mar 2013 09:50:47 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> I still don't have the mutual exclusivity working; you can't go
>> subword-superword with `M-x superword-mode'. It goes
>> subword-subword disabled->superword and you have to do
>> `M-x superword-mode' twice. See attached.
SM> Feel free to install, thank you.
OK; done.
SM> This should be (when subword-mode (superword-mode -1))
SM> And this should be (when superword-mode (subword-mode -1))
Oh I see, it runs after. Thanks for explaining. Fixed.
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-26 19:04 ` superword-mode (was: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.) Ted Zlatanov
2013-03-27 1:23 ` superword-mode Stefan Monnier
@ 2013-03-27 15:03 ` Davis Herring
2013-03-27 15:19 ` superword-mode Ted Zlatanov
2013-03-28 23:00 ` superword-mode Ted Zlatanov
2 siblings, 1 reply; 42+ messages in thread
From: Davis Herring @ 2013-03-27 15:03 UTC (permalink / raw)
To: Ted Zlatanov; +Cc: Emacs development discussions
On 03/26/2013 01:04 PM, Ted Zlatanov wrote:
> +(defun subword-right (&optional arg)
> + (interactive "p")
> + (subword-forward arg))
Shouldn't this be bidi-aware (as is right-word)?
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-27 15:03 ` superword-mode Davis Herring
@ 2013-03-27 15:19 ` Ted Zlatanov
2013-03-27 15:33 ` superword-mode Ted Zlatanov
0 siblings, 1 reply; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-27 15:19 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 357 bytes --]
On Wed, 27 Mar 2013 09:03:06 -0600 Davis Herring <herring@lanl.gov> wrote:
DH> On 03/26/2013 01:04 PM, Ted Zlatanov wrote:
>> +(defun subword-right (&optional arg)
>> + (interactive "p")
>> + (subword-forward arg))
DH> Shouldn't this be bidi-aware (as is right-word)?
(: .tniop doog ,seY
Does the attached work properly? If yes I can install.
Ted
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: superword-mode-bidifix.patch --]
[-- Type: text/x-diff, Size: 1082 bytes --]
=== modified file 'lisp/progmodes/subword.el'
--- lisp/progmodes/subword.el 2013-03-27 14:04:34 +0000
+++ lisp/progmodes/subword.el 2013-03-27 15:10:46 +0000
@@ -168,8 +168,6 @@
(put 'subword-forward 'CUA 'move)
-(defalias 'subword-right 'subword-forward)
-
(defun subword-backward (&optional arg)
"Do the same as `backward-word' but on subwords.
See the command `subword-mode' for a description of subwords.
@@ -177,7 +175,19 @@
(interactive "p")
(subword-forward (- (or arg 1))))
-(defalias 'subword-left 'subword-backward)
+(defun subword-right (&optional arg)
+ "Do the same as `right-word' but on subwords."
+ (interactive "p")
+ (if (eq (current-bidi-paragraph-direction) 'left-to-right)
+ (subword-forward arg)
+ (subword-backward arg)))
+
+(defun subword-left (&optional arg)
+ "Do the same as `left-word' but on subwords."
+ (interactive "p")
+ (if (eq (current-bidi-paragraph-direction) 'left-to-right)
+ (subword-backward arg)
+ (subword-forward arg)))
(defun subword-mark (arg)
"Do the same as `mark-word' but on subwords.
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-27 15:19 ` superword-mode Ted Zlatanov
@ 2013-03-27 15:33 ` Ted Zlatanov
2013-03-27 16:33 ` superword-mode Stefan Monnier
0 siblings, 1 reply; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-27 15:33 UTC (permalink / raw)
To: emacs-devel
Overriding the CUA `left-word' and `right-word' command works OK with
`subword-mode' and `superword-mode', except that S-C-left and S-C-right
don't initiate a selection. I don't know if that's trivially fixed or
not.
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-27 15:33 ` superword-mode Ted Zlatanov
@ 2013-03-27 16:33 ` Stefan Monnier
2013-03-27 19:31 ` superword-mode Ted Zlatanov
0 siblings, 1 reply; 42+ messages in thread
From: Stefan Monnier @ 2013-03-27 16:33 UTC (permalink / raw)
To: emacs-devel
> Overriding the CUA `left-word' and `right-word' command works OK with
> `subword-mode' and `superword-mode', except that S-C-left and S-C-right
> don't initiate a selection. I don't know if that's trivially fixed or
> not.
Yes, the fix is in the interactive spec (which needs a "^").
Stefan
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-27 16:33 ` superword-mode Stefan Monnier
@ 2013-03-27 19:31 ` Ted Zlatanov
2013-03-27 22:23 ` superword-mode Stefan Monnier
0 siblings, 1 reply; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-27 19:31 UTC (permalink / raw)
To: emacs-devel
On Wed, 27 Mar 2013 12:33:26 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> Overriding the CUA `left-word' and `right-word' command works OK with
>> `subword-mode' and `superword-mode', except that S-C-left and S-C-right
>> don't initiate a selection. I don't know if that's trivially fixed or
>> not.
SM> Yes, the fix is in the interactive spec (which needs a "^").
At the risk of sounding like an idiot, I tried
(interactive "^p")
and it didn't work, I still don't start a selection with S-C-left/right:
#+begin_src lisp
(defun subword-forward (&optional arg)
...
(interactive "p")
...
(defun subword-backward (&optional arg)
...
(interactive "^p")
...
(defun subword-right (&optional arg)
"Do the same as `right-word' but on subwords."
(interactive "^p")
...
(defun subword-left (&optional arg)
"Do the same as `left-word' but on subwords."
(interactive "^p")
#+end_src
I hope it's something trivial I've missed.
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-27 19:31 ` superword-mode Ted Zlatanov
@ 2013-03-27 22:23 ` Stefan Monnier
0 siblings, 0 replies; 42+ messages in thread
From: Stefan Monnier @ 2013-03-27 22:23 UTC (permalink / raw)
To: emacs-devel
> I hope it's something trivial I've missed.
Must be, tho I don't see it either just now,
Stefan
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-26 19:04 ` superword-mode (was: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.) Ted Zlatanov
2013-03-27 1:23 ` superword-mode Stefan Monnier
2013-03-27 15:03 ` superword-mode Davis Herring
@ 2013-03-28 23:00 ` Ted Zlatanov
2013-03-29 13:26 ` superword-mode Ted Zlatanov
2013-03-29 21:18 ` superword-mode Stefan Monnier
2 siblings, 2 replies; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-28 23:00 UTC (permalink / raw)
To: emacs-devel; +Cc: Juanma Barranquero
Juanma caught the problem that `forward-symbol' is autoloaded from
`thingatpt.el' and `C-M-f' actually runs `forward-sexp'. Oops. So
`superword-mode' is slightly broken currently.
I need to know if I should:
1) use `forward-sexp' instead of `forward-symbol'
2) implement a local version of `forward-symbol'
3) autoload `forward-symbol'
I'm leaning towards (1) because I think it would work great for CFEngine
and Perl and C editing. I don't want to assume it's the right solution,
though, so let me know what you think.
Thanks
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-28 23:00 ` superword-mode Ted Zlatanov
@ 2013-03-29 13:26 ` Ted Zlatanov
2013-03-29 16:23 ` superword-mode Andreas Röhler
2013-03-29 20:16 ` superword-mode Davis Herring
2013-03-29 21:18 ` superword-mode Stefan Monnier
1 sibling, 2 replies; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-29 13:26 UTC (permalink / raw)
To: emacs-devel
On Thu, 28 Mar 2013 19:00:11 -0400 Ted Zlatanov <tzz@lifelogs.com> wrote:
TZ> Juanma caught the problem that `forward-symbol' is autoloaded from
TZ> `thingatpt.el' and `C-M-f' actually runs `forward-sexp'. Oops. So
TZ> `superword-mode' is slightly broken currently.
TZ> I need to know if I should:
TZ> 1) use `forward-sexp' instead of `forward-symbol'
TZ> 2) implement a local version of `forward-symbol'
TZ> 3) autoload `forward-symbol'
TZ> I'm leaning towards (1) because I think it would work great for CFEngine
TZ> and Perl and C editing. I don't want to assume it's the right solution,
TZ> though, so let me know what you think.
In order to avoid breakage I implemented (1) but please tell me if you
think that's the wrong decision. Thanks.
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-29 13:26 ` superword-mode Ted Zlatanov
@ 2013-03-29 16:23 ` Andreas Röhler
2013-03-29 16:43 ` superword-mode Ted Zlatanov
2013-03-29 20:16 ` superword-mode Davis Herring
1 sibling, 1 reply; 42+ messages in thread
From: Andreas Röhler @ 2013-03-29 16:23 UTC (permalink / raw)
To: emacs-devel; +Cc: Ted Zlatanov
Am 29.03.2013 14:26, schrieb Ted Zlatanov:
> On Thu, 28 Mar 2013 19:00:11 -0400 Ted Zlatanov <tzz@lifelogs.com> wrote:
>
> TZ> Juanma caught the problem that `forward-symbol' is autoloaded from
> TZ> `thingatpt.el' and `C-M-f' actually runs `forward-sexp'. Oops. So
> TZ> `superword-mode' is slightly broken currently.
>
> TZ> I need to know if I should:
>
> TZ> 1) use `forward-sexp' instead of `forward-symbol'
> TZ> 2) implement a local version of `forward-symbol'
> TZ> 3) autoload `forward-symbol'
>
> TZ> I'm leaning towards (1) because I think it would work great for CFEngine
> TZ> and Perl and C editing. I don't want to assume it's the right solution,
> TZ> though, so let me know what you think.
>
> In order to avoid breakage I implemented (1) but please tell me if you
> think that's the wrong decision. Thanks.
>
> Ted
>
>
>
Hi,
IMO that can't work, as forward-sexp has a long-time bug wrt to strings.
Lately offered a solution for end-of-sexp from thingatpt.el, which applies likewise.
BTW why not simply change the syntax-class using modify-syntax-entry?
Thanks,
Andreas
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-29 16:23 ` superword-mode Andreas Röhler
@ 2013-03-29 16:43 ` Ted Zlatanov
2013-03-29 17:49 ` superword-mode Andreas Röhler
0 siblings, 1 reply; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-29 16:43 UTC (permalink / raw)
To: emacs-devel
On Fri, 29 Mar 2013 17:23:24 +0100 Andreas Röhler <andreas.roehler@online.de> wrote:
AR> Am 29.03.2013 14:26, schrieb Ted Zlatanov:
>> On Thu, 28 Mar 2013 19:00:11 -0400 Ted Zlatanov <tzz@lifelogs.com> wrote:
>>
TZ> Juanma caught the problem that `forward-symbol' is autoloaded from
TZ> `thingatpt.el' and `C-M-f' actually runs `forward-sexp'. Oops. So
TZ> `superword-mode' is slightly broken currently.
>>
TZ> I need to know if I should:
>>
TZ> 1) use `forward-sexp' instead of `forward-symbol'
TZ> 2) implement a local version of `forward-symbol'
TZ> 3) autoload `forward-symbol'
>>
TZ> I'm leaning towards (1) because I think it would work great for CFEngine
TZ> and Perl and C editing. I don't want to assume it's the right solution,
TZ> though, so let me know what you think.
>>
>> In order to avoid breakage I implemented (1) but please tell me if you
>> think that's the wrong decision. Thanks.
AR> IMO that can't work, as forward-sexp has a long-time bug wrt to
AR> strings.
AR> Lately offered a solution for end-of-sexp from thingatpt.el, which
AR> applies likewise.
Sorry, I can't parse that sentence, and I don't have a reference for
this solution.
AR> BTW why not simply change the syntax-class using modify-syntax-entry?
That was my original approach, but it's incorrect according to Stefan.
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-29 16:43 ` superword-mode Ted Zlatanov
@ 2013-03-29 17:49 ` Andreas Röhler
2013-03-29 18:10 ` superword-mode Ted Zlatanov
0 siblings, 1 reply; 42+ messages in thread
From: Andreas Röhler @ 2013-03-29 17:49 UTC (permalink / raw)
To: emacs-devel; +Cc: Ted Zlatanov, Stefan Monnier
Am 29.03.2013 17:43, schrieb Ted Zlatanov:
> On Fri, 29 Mar 2013 17:23:24 +0100 Andreas Röhler <andreas.roehler@online.de> wrote:
>
> AR> Am 29.03.2013 14:26, schrieb Ted Zlatanov:
>>> On Thu, 28 Mar 2013 19:00:11 -0400 Ted Zlatanov <tzz@lifelogs.com> wrote:
>>>
> TZ> Juanma caught the problem that `forward-symbol' is autoloaded from
> TZ> `thingatpt.el' and `C-M-f' actually runs `forward-sexp'. Oops. So
> TZ> `superword-mode' is slightly broken currently.
>>>
> TZ> I need to know if I should:
>>>
> TZ> 1) use `forward-sexp' instead of `forward-symbol'
> TZ> 2) implement a local version of `forward-symbol'
> TZ> 3) autoload `forward-symbol'
>>>
> TZ> I'm leaning towards (1) because I think it would work great for CFEngine
> TZ> and Perl and C editing. I don't want to assume it's the right solution,
> TZ> though, so let me know what you think.
>>>
>>> In order to avoid breakage I implemented (1) but please tell me if you
>>> think that's the wrong decision. Thanks.
>
> AR> IMO that can't work, as forward-sexp has a long-time bug wrt to
> AR> strings.
>
> AR> Lately offered a solution for end-of-sexp from thingatpt.el, which
> AR> applies likewise.
>
> Sorry, I can't parse that sentence, and I don't have a reference for
> this solution.
bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
>
> AR> BTW why not simply change the syntax-class using modify-syntax-entry?
>
> That was my original approach, but it's incorrect according to Stefan.
>
Oh, because python-mode.el proceeds that way? :)
Can't see that stand in this thread, will cc it to him.
Assume it's a misunderstanding, as mode-specific syntax-changes are common.
BTW forward-sexp docu says it's not usable from inside a string. Once the bug is fixed,
that might be dropped.
Best,
Andreas
> Ted
>
>
>
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-29 17:49 ` superword-mode Andreas Röhler
@ 2013-03-29 18:10 ` Ted Zlatanov
2013-03-29 18:50 ` superword-mode Andreas Röhler
0 siblings, 1 reply; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-29 18:10 UTC (permalink / raw)
To: emacs-devel
On Fri, 29 Mar 2013 18:49:04 +0100 Andreas Röhler <andreas.roehler@online.de> wrote:
AR> IMO that can't work, as forward-sexp has a long-time bug wrt to
AR> strings.
AR> bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
I'm not convinced that the bug shouldn't be fixed instead.
AR> BTW why not simply change the syntax-class using modify-syntax-entry?
>>
>> That was my original approach, but it's incorrect according to Stefan.
>>
AR> Oh, because python-mode.el proceeds that way? :)
AR> Can't see that stand in this thread, will cc it to him.
Start with
http://thread.gmane.org/gmane.emacs.diffs/119990/focus=158194
or gather the thread from this article upwards. For `cfengine-mode' I
modified all the motion to use \_> and \_< instead of \> and \<
AR> Assume it's a misunderstanding, as mode-specific syntax-changes are common.
AR> BTW forward-sexp docu says it's not usable from inside a string. Once the bug is fixed,
AR> that might be dropped.
So you're saying that `superword-mode' should simply add "_" to the word
syntax? Or something else? Sorry to be dense.
Another possibility is to make the motion context-sensitive, so we move
by word inside strings or comments but by sexp or symbol outside them.
(I actually discovered I like using `forward-sexp' with `superword-mode'
in non-Lisp languages, except through strings. In Lisp it jumps too
much.)
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-29 18:10 ` superword-mode Ted Zlatanov
@ 2013-03-29 18:50 ` Andreas Röhler
2013-03-29 19:04 ` superword-mode Ted Zlatanov
0 siblings, 1 reply; 42+ messages in thread
From: Andreas Röhler @ 2013-03-29 18:50 UTC (permalink / raw)
To: emacs-devel; +Cc: Ted Zlatanov, Stefan Monnier
Am 29.03.2013 19:10, schrieb Ted Zlatanov:
> On Fri, 29 Mar 2013 18:49:04 +0100 Andreas Röhler <andreas.roehler@online.de> wrote:
>
> AR> IMO that can't work, as forward-sexp has a long-time bug wrt to
> AR> strings.
>
> AR> bug#13973: Subject: 24.3; thingatpt.el, end-of-sexp
>
> I'm not convinced that the bug shouldn't be fixed instead.
That would help, but not make the use of forward-sexp perfect for your purpose.
Simply because a sexp is still a wider object than the kind you address.
>
> AR> BTW why not simply change the syntax-class using modify-syntax-entry?
>>>
>>> That was my original approach, but it's incorrect according to Stefan.
>>>
>
> AR> Oh, because python-mode.el proceeds that way? :)
> AR> Can't see that stand in this thread, will cc it to him.
>
> Start with
>
> http://thread.gmane.org/gmane.emacs.diffs/119990/focus=158194
>
Can't see any comment from Stefan with this meaning. CC again, forgot previously.
> or gather the thread from this article upwards. For `cfengine-mode' I
> modified all the motion to use \_> and \_< instead of \> and \<
>
> AR> Assume it's a misunderstanding, as mode-specific syntax-changes are common.
>
> AR> BTW forward-sexp docu says it's not usable from inside a string. Once the bug is fixed,
> AR> that might be dropped.
>
> So you're saying that `superword-mode' should simply add "_" to the word
> syntax?
Yes. To be switched on/off with the mode. Maybe I'm misunderstanding the purpose?
Or something else? Sorry to be dense.
>
> Another possibility is to make the motion context-sensitive, so we move
> by word inside strings or comments but by sexp or symbol outside them.
>
> (I actually discovered I like using `forward-sexp' with `superword-mode'
> in non-Lisp languages,
Sure it will work mostly. It might work always - beside of the bugs still unseen :)
Cheers
except through strings. In Lisp it jumps too
> much.)
>
> Ted
>
>
>
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-29 18:50 ` superword-mode Andreas Röhler
@ 2013-03-29 19:04 ` Ted Zlatanov
0 siblings, 0 replies; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-29 19:04 UTC (permalink / raw)
To: emacs-devel
On Fri, 29 Mar 2013 19:50:12 +0100 Andreas Röhler <andreas.roehler@online.de> wrote:
AR> Am 29.03.2013 19:10, schrieb Ted Zlatanov:
>> So you're saying that `superword-mode' should simply add "_" to the word
>> syntax?
AR> Yes. To be switched on/off with the mode. Maybe I'm misunderstanding the purpose?
(btw, your e-mail client is mangling my plain text, I'm not sure what happened)
I understand your point, and perhaps it's OK in `superword-mode' because
we can make that modification implicit in choosing to use that mode. It
was not OK in `cfengine-mode', I quote the last word in that exchange:
TZZ> Or are you saying users don't expect _ to be part of a
TZZ> word and it's unconventional to make it so?
SM> Exactly. Many users actually like _ to be part of a word, but these
SM> are user-preferences (and we should indeed define a
SM> words-are-symbols-mode for those users since what they really want
SM> is for M-f, M-t, M-DEL to move by symbols rather than by words).
`cfengine-mode' works properly now so it's not under discussion, but I
mention it for context.
So I'd be OK with whatever direction is chosen by the Emacs maintainers.
I can change `superword-mode' to DTRT; I have no strong personal
preference either way.
Also, I don't think you need to CC Stefan directly, he reads this list.
(I personally prefer to get no CC off-list, unless you want to be sure I
won't miss the beginning of a thread, and I've set my headers
accordingly. This is not to be anti-social but simply because I use
GMane and often leave e-mail unseen for weeks and months.)
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-29 13:26 ` superword-mode Ted Zlatanov
2013-03-29 16:23 ` superword-mode Andreas Röhler
@ 2013-03-29 20:16 ` Davis Herring
1 sibling, 0 replies; 42+ messages in thread
From: Davis Herring @ 2013-03-29 20:16 UTC (permalink / raw)
To: emacs-devel
> TZ> 1) use `forward-sexp' instead of `forward-symbol'
> TZ> 2) implement a local version of `forward-symbol'
> TZ> 3) autoload `forward-symbol'
>
> In order to avoid breakage I implemented (1) but please tell me if you
> think that's the wrong decision. Thanks.
I think it's certainly wrong to do (1) -- a balanced set of parentheses
or so is not a natural extension of a word the way a symbol is, and it
seems useful for M-f and C-M-f to remain distinct under
`superword-mode'. I don't have a preference between (2) and (3), except
to say that either the (2) version or the thingatpt version could be
(re)written to use \_< and \_> just like `cfengine-mode'.
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-28 23:00 ` superword-mode Ted Zlatanov
2013-03-29 13:26 ` superword-mode Ted Zlatanov
@ 2013-03-29 21:18 ` Stefan Monnier
2013-03-30 1:34 ` superword-mode Ted Zlatanov
2013-03-30 6:28 ` superword-mode Andreas Röhler
1 sibling, 2 replies; 42+ messages in thread
From: Stefan Monnier @ 2013-03-29 21:18 UTC (permalink / raw)
To: emacs-devel
> 1) use `forward-sexp' instead of `forward-symbol'
> 2) implement a local version of `forward-symbol'
> 3) autoload `forward-symbol'
The problem with forward-sexp is that it won't do the same as
forward-symbol if it bumps into a parenthesis along the way.
Also if the user wants forward-sexp she can just use C-M-f.
So for all these reasons I think option 1 is not very good.
Note also that there's no reason why forward-symbol should be defined in
thingatpt.el, so it could also be moved to subr.el.
Stefan
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-29 21:18 ` superword-mode Stefan Monnier
@ 2013-03-30 1:34 ` Ted Zlatanov
2013-03-30 1:36 ` superword-mode Ted Zlatanov
2013-03-30 6:28 ` superword-mode Andreas Röhler
1 sibling, 1 reply; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-30 1:34 UTC (permalink / raw)
To: emacs-devel
On Fri, 29 Mar 2013 17:18:34 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> 1) use `forward-sexp' instead of `forward-symbol'
>> 2) implement a local version of `forward-symbol'
>> 3) autoload `forward-symbol'
SM> The problem with forward-sexp is that it won't do the same as
SM> forward-symbol if it bumps into a parenthesis along the way.
SM> Also if the user wants forward-sexp she can just use C-M-f.
SM> So for all these reasons I think option 1 is not very good.
SM> Note also that there's no reason why forward-symbol should be defined in
SM> thingatpt.el, so it could also be moved to subr.el.
OK; `superword-mode' is back to `forward-symbol' and I moved the
`forward-whitespace', `forward-symbol', and `forward-same-syntax'
commands to subr.el (reasoning that they are closely related, have no
external dependencies, and are very useful generally).
If that was not OK, please adjust accordingly.
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-30 1:34 ` superword-mode Ted Zlatanov
@ 2013-03-30 1:36 ` Ted Zlatanov
0 siblings, 0 replies; 42+ messages in thread
From: Ted Zlatanov @ 2013-03-30 1:36 UTC (permalink / raw)
To: emacs-devel
On Fri, 29 Mar 2013 21:34:23 -0400 Ted Zlatanov <tzz@lifelogs.com> wrote:
TZ> OK; `superword-mode' is back to `forward-symbol' and I moved the
TZ> `forward-whitespace', `forward-symbol', and `forward-same-syntax'
TZ> commands to subr.el (reasoning that they are closely related, have no
TZ> external dependencies, and are very useful generally).
I gave all three the "^p" interactive syntax but still, the CUA S-C-left
and S-C-right keystrokes do not initiate a selection. Hmmm.
Ted
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: superword-mode
2013-03-29 21:18 ` superword-mode Stefan Monnier
2013-03-30 1:34 ` superword-mode Ted Zlatanov
@ 2013-03-30 6:28 ` Andreas Röhler
1 sibling, 0 replies; 42+ messages in thread
From: Andreas Röhler @ 2013-03-30 6:28 UTC (permalink / raw)
To: emacs-devel
Am 29.03.2013 22:18, schrieb Stefan Monnier:
>> 1) use `forward-sexp' instead of `forward-symbol'
>> 2) implement a local version of `forward-symbol'
>> 3) autoload `forward-symbol'
>
> The problem with forward-sexp is that it won't do the same as
> forward-symbol if it bumps into a parenthesis along the way.
> Also if the user wants forward-sexp she can just use C-M-f.
> So for all these reasons I think option 1 is not very good.
>
> Note also that there's no reason why forward-symbol should be defined in
> thingatpt.el, so it could also be moved to subr.el.
>
>
> Stefan
>
>
+1
^ permalink raw reply [flat|nested] 42+ messages in thread
end of thread, other threads:[~2013-03-30 6:28 UTC | newest]
Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <E1UIiBH-0005sm-Vy@vcs.savannah.gnu.org>
2013-03-21 23:44 ` [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax Stefan Monnier
2013-03-21 23:49 ` Ted Zlatanov
2013-03-22 1:32 ` Stefan Monnier
2013-03-22 13:03 ` Ted Zlatanov
2013-03-22 13:14 ` Tom Tromey
2013-03-22 13:38 ` Ted Zlatanov
2013-03-22 14:18 ` Stefan Monnier
2013-03-22 14:46 ` Ted Zlatanov
2013-03-22 17:30 ` Stefan Monnier
2013-03-22 19:13 ` Ted Zlatanov
2013-03-23 16:01 ` Stefan Monnier
2013-03-26 9:17 ` Ted Zlatanov
2013-03-26 17:06 ` Stefan Monnier
2013-03-26 19:04 ` superword-mode (was: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.) Ted Zlatanov
2013-03-27 1:23 ` superword-mode Stefan Monnier
2013-03-27 3:18 ` superword-mode Masatake YAMATO
2013-03-27 9:31 ` superword-mode Andreas Schwab
2013-03-27 13:06 ` superword-mode Ted Zlatanov
2013-03-27 13:14 ` superword-mode Stefan Monnier
2013-03-27 13:04 ` superword-mode Ted Zlatanov
2013-03-27 13:50 ` superword-mode Stefan Monnier
2013-03-27 14:06 ` superword-mode Ted Zlatanov
2013-03-27 15:03 ` superword-mode Davis Herring
2013-03-27 15:19 ` superword-mode Ted Zlatanov
2013-03-27 15:33 ` superword-mode Ted Zlatanov
2013-03-27 16:33 ` superword-mode Stefan Monnier
2013-03-27 19:31 ` superword-mode Ted Zlatanov
2013-03-27 22:23 ` superword-mode Stefan Monnier
2013-03-28 23:00 ` superword-mode Ted Zlatanov
2013-03-29 13:26 ` superword-mode Ted Zlatanov
2013-03-29 16:23 ` superword-mode Andreas Röhler
2013-03-29 16:43 ` superword-mode Ted Zlatanov
2013-03-29 17:49 ` superword-mode Andreas Röhler
2013-03-29 18:10 ` superword-mode Ted Zlatanov
2013-03-29 18:50 ` superword-mode Andreas Röhler
2013-03-29 19:04 ` superword-mode Ted Zlatanov
2013-03-29 20:16 ` superword-mode Davis Herring
2013-03-29 21:18 ` superword-mode Stefan Monnier
2013-03-30 1:34 ` superword-mode Ted Zlatanov
2013-03-30 1:36 ` superword-mode Ted Zlatanov
2013-03-30 6:28 ` superword-mode Andreas Röhler
2013-03-22 14:13 ` [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.