ergoemacs / ergoemacs-mode

ergoemacs-mode
ergoemacs.github.io/
GNU General Public License v3.0
293 stars 35 forks source link

Sexp movements? #336

Closed tuhdo closed 9 years ago

tuhdo commented 9 years ago

@xahlee @mlf176f2 I think the two default sexp movements: forward-sexp and backward-sexp and kill-sexp are really useful. It's not only usable in Lisp modes but can be used in other modes to operate on symbols. May you consider add it as part of Ergoemacs design, @xahlee ?

xahlee commented 9 years ago

i didn't find forward-sexp that useful, in comparsion to a similar xah-forward-right-bracket, which just move to any next occurences of left bracket.

same for the backward version.

i find that i actually use xah-backward-left-bracket a lot.

here's my usage percentage

375336 22.33% self-insert-command ... 23512 1.40% newline 143249 8.52% next-line 22750 1.35% xah-backward-left-bracket ... 20976 1.25% subword-forward 18567 1.10% subword-backward 18460 1.10% save-buffer 17221 1.02% backward-char 15369 0.91% isearch-repeat-forward 14697 0.87% org-self-insert-command 13096 0.78% forward-char 12496 0.74% xah-shrink-whitespaces 12273 0.73% xah-copy-line-or-region 12202 0.73% xah-forward-right-bracket 10916 0.65% backward-kill-word 10242 0.61% other-window 9963 0.59% isearch-forward ...

the sexp version is almost never used...

Xah

On Fri, Mar 13, 2015 at 1:38 PM, Tu Do notifications@github.com wrote:

@xahlee https://github.com/xahlee @mlf176f2 https://github.com/mlf176f2 I think the two default sexp movements: forward-sexp and backward-sexp and kill-sexp are really useful. It's not only usable in Lisp modes but can be used in other modes to operate on symbols. May you consider add it as part of Ergoemacs design, @xahlee https://github.com/xahlee ?

— Reply to this email directly or view it on GitHub https://github.com/ergoemacs/ergoemacs-mode/issues/336.

tuhdo commented 9 years ago

Well, I use it frequently. It is useful to jump over symbols, not just closing/opening parens/brackets, i.e. thisIsVeryLongVariableName. It is applicable in not only Lisp but any programming major modes.

xahlee commented 9 years ago

the other version is more general than sexp-forward.

Xah

On Sat, Mar 14, 2015 at 9:50 PM, Tu Do notifications@github.com wrote:

Well, I use it frequently. It is useful to jump over symbols, not just closing/opening parens/brackets, i.e. thisIsVeryLongVariableName. It is applicable in not only Lisp but any programming major modes.

— Reply to this email directly or view it on GitHub https://github.com/ergoemacs/ergoemacs-mode/issues/336#issuecomment-80856014 .

tuhdo commented 9 years ago

@xahlee Probably I should say symbol, since saying sexp makes an impression that I'm talking about text movement in Lisp only. What I really meant is forward-symbol (you can define backward-symbol with negative argument supplied to forward-symbol). It is useful in case like this:

var longVariableName1, longVariableName2, longVariableName3;

forward-symbol jumps over symbols, not words, which is quite useful imo.

xahlee commented 9 years ago

Tu Do,

am not sure what you are saying. forward-sexp is for moving cursor among brackets, any brackets, as if treating them as a tree. So, it may skip some brackets.

forward-symbol is similar to forward-word, which move cursor over a sequence of letters or plus underscore and hyphen.

so, i'm not sure what you mean.

if you suggest forward-sexp be included in ergoemacs-mode, my response is that i have forward-bracket, which is more general. But you never answered to that.

if you mean forward-symbol, ergoemacs-mode has that already, Alt+o.

Xah

On Sun, Mar 15, 2015 at 9:40 PM, Tu Do notifications@github.com wrote:

@xahlee https://github.com/xahlee Probably I should say symbol, since saying sexp makes an impression that I'm talking about text movement in Lisp only. What I really meant is forward-symbol (you can define backward-symbol with negative argument supplied to forward-symbol). It is useful in case like this:

var longVariableName1, longVariableName2, longVariableName3;

forward-symbol jumps over symbols, not words, which is quite useful imo.

— Reply to this email directly or view it on GitHub https://github.com/ergoemacs/ergoemacs-mode/issues/336#issuecomment-81408935 .

tuhdo commented 9 years ago

forward-sexp is for moving cursor among brackets, any brackets, as if treating them as a tree. So, it may skip some brackets.

This is part of it. If you try forward-sexp on a symbol, it will move over that symbol. For example:

var this_is_a_symbol;

If the cursor is just after var and you run forward-sexp (bound to C-M-f by default), it will move point to the ; character. Of course, when point is on a bracket/paren, running forward-sexp moves the cursor to the next closing bracket/paren.

forward-symbol is a subset of forward-sexp: it only moves forward a symbol.

if you mean forward-symbol, ergoemacs-mode has that already, Alt+o.

It only forwards a word, not symbol For example:

var a_long_variable_name;

If point is after var, Alt+o only moves the cursor above _ character, while forward-symbol moves the cursor to ;.

It seems like you don't enable subword-mode by default, so Alt+o skips over a symbol. But I think skipping a word and skipping a symbol are different things, and it's nice to have both.

tuhdo commented 9 years ago

@xahlee subword-mode allows you to navigate words inside a symbol like this:

var longVariableName;

Assume cursor after var, executing forward-word moves point on V character.

xahlee commented 9 years ago

Tu Do,

ultimately, you'll have to talk to Matt about suggestions to ergoemacs-mode.

Yes i see your point. Yes, forward-sexp move over symbols too, basically it moves over a node. Depending on where the cursor is, sometimes it'll just jump over a symbol as if forward-symbol, but if cursor is at end of a bracket it'll jump over the next complete sexp expression. Over all, the behavior is not simple, since it treats the text as a tree.

also, by gnu emacs default, it has a key Ctrl+alt+rightArrow.

so you are suggesting adding forward-symbol and backward-symbol to ergoemacs-mode? Do you mean adding a keybinding to them?

in anyway, i don't think it's a good idea at all. It's relatively rarely used. Not general enough for other langs.

Xah

On Sun, Mar 15, 2015 at 10:15 PM, Tu Do notifications@github.com wrote:

forward-sexp is for moving cursor among brackets, any brackets, as if treating them as a tree. So, it may skip some brackets.

This is part of it. If you try forward-sexp on a symbol, it will move over that symbol. For example:

var this_is_a_symbol;

If the cursor is just after var and you run forward-sexp (bound to C-M-f by default), it will move point to the ; character. Of course, when point is on a bracket/paren, running forward-sexp moves the cursor to the next closing bracket/paren.

forward-symbol is a subset of forward-sexp: it only moves forward a symbol.

if you mean forward-symbol, ergoemacs-mode has that already, Alt+o.

It only forwards a word, not symbol For example:

var a_long_variable_name;

If point is after var, Alt+o only moves the cursor above _ character, while forward-symbol moves the cursor to ;.

It seems like you don't enable subword-mode by default, so Alt+o skips over a symbol. But I think skipping a word and skipping a symbol are different things, and it's nice to have both.

— Reply to this email directly or view it on GitHub https://github.com/ergoemacs/ergoemacs-mode/issues/336#issuecomment-81421836 .

mattfidler commented 9 years ago

I'm not sure who uses forward-sexp, but I believe the usage is common in certain circles. For example, David Capello uses it frequently enough to replace it in his ergoprog

http://davidcapello.com/programming/keyboard-layout/

This used to be one of the ergoemacs-mode themes. I removed the theme, but don't mind adding the sexp option back.

My current approach is to try to keep the themes general and let options be turned on and off with ergoemacs-mode. That way, even if someone like Xah doesn't use the command frequently, the subset that uses that command frequently will be able to use it efficiently. You should really count your own usage to see what applies to you.

I personally have no objection to moving this command to a theme option. Since Xah has the command frequencies, I think I will leave it disabled for now. If there is some evidence that more people use this option, I will make it a default option.

mattfidler commented 9 years ago

You should be able to enable this option from the menu. It is now under disputed keys.

You can also enable it by

(ergoemacs-require 'move-sexp)