Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: make changing to insert mode push mark by default? #71

Open
DanLanglois opened this issue Mar 17, 2019 · 2 comments
Open

feature: make changing to insert mode push mark by default? #71

DanLanglois opened this issue Mar 17, 2019 · 2 comments

Comments

@DanLanglois
Copy link
Contributor

DanLanglois commented Mar 17, 2019

I'm considering this:
xahlee / xah-fly-keys / xah-fly-keys.el

620 (push-mark (point) t)

That is in 'xah-delete-backward-bracket-pair ()'
"Delete the matching brackets/quotes to the left of cursor.."

It occurs to me that something along these lines could also be expected of 'xah-fly-insert-mode-init ()'
"Set insertion mode keys"

Some commands set the mark as a side-effect. And, once the mark exists in a buffer, it normally never ceases to exist. And, in addition to the mark, each buffer has a mark ring which is a list of markers containing previous values of the mark. When editing commands change the mark, they should normally save the old value of the mark on the mark ring.

So I am pondering 'set-mark position', and how this function sets the current buffer's mark to 'position', and pushes a copy of the previous mark onto mark-ring. What about having 'xah-fly-insert-mode-init ()' do this? I also wonder about 'deactivate-mark'. Note that when I go into insert mode, this changes my cursor to a bar. That's fine, but I wonder about also this being a good moment to remember where the last edition was by pushing a mark. A related concern is I can imagine it turning out to be useful if we have a variable for 'point at start of insert mode'. If we are changing cursor type, and updating the mode line, then is this also a moment for setting markers or such? Keeping track of 'insert-beginning', perhaps.

I'm looking at the emacs docs about moving marker positions. You can change the position of an existing marker. Or, that is, you can move 'marker' to 'position' in buffer. I'm thinking also, of how there are many
commands that insert text, which also set the mark at the other end of the inserted text, without activating it. This lets you easily return to that position.

It seems like one idea, then, is that when I go into insert mode, I could get a @samp{Mark set} being shown to me in the echo area.

My point here is partially just about high-level best practices, when using emacs -- I wonder, about the workflow where most of the time spent on a buffer (besides, obviously, typing text) is spent moving the cursor around and marking regions. I picture using isearch or whathaveyou, phi-search, and going to a specific place in the visible part of the buffer. And currently, for me, it's like this: even if it is 2 words away: search your way there. If search is not enough: use M-x grep! But then we come to marking stuff. If I search to the beginning (or end) of the region, shall we say, then I want to set mark. Maybe just switching to insert mode could do this automatically for me?

To review, my debate is what exactly should happen when I switch to insert mode. I think moving the mark, or setting a new one, would be convenient, if this happens by default. If I look in 'xah-fly-keys.el', it seems that 'set-marker' is never used. Nor is there a variable such as 'xah-fly-keys/insert-origin'. What about 'push-mark'? Well, I started by mentioning that this is found in 'xah-delete-backward-bracket-pair'. It's also found in 'xah-delete-forward-bracket-pairs'. Beyond that, there are other cases. I'm looking at 'xah-extend-selection'. Interesting. But I will try to avoid distraction.

Once you get beyond basic cursor control, there are a few things that are integrated, here. I have not, actually, gotten beyond basic cursor control. I debate what I might like best, for this. I have emphasized elsewhere (in my issues that I've opened), that I like to jump several sets at once by typing a number before a command, for example. But leaving 'basic cursor control' aside, there are, shall we say, other movement commands. I'm considering how one makes use of popping a mark and jumping to it. My impression is that normally, when a new mark is set, the old one should go on the mark-ring. This seems like a reason to use push-mark and pop-mark, not set-mark. I find this all interesting especially, because I am coming around to the view that the mark saves a location for my (the user's) convenience. Yet, I can also remember a location for internal use in the Lisp program, and store it in a Lisp variable.

In any case, I look at 'xah-fly-keys', and actually, off the cuff, I don't see or recall how to pop off the top element of mark-ring and make that mark become the buffer's actual mark. I have ingenuously searched in 'xah-fly-keys.el', for pop-mark, and gotten no hits. Maybe this isn't commonly used, because it does not move point in the buffer. But what about 'switch point and mark'? This is, on dvorak, mapped to 'o'. Or, 'exchange-point-and-mark' is. Fine..

..but I do think maybe 'Mark set' could happen simply by default when I go into insert mode.

Simple enough to experiment with this, I'll create a 'develop' branch on my own fork..

@DanLanglois
Copy link
Contributor Author

DanLanglois commented Mar 17, 2019

Some notes:

execute-extended-command is SPC-ENTER. And, alternatively, M-x is 'a'. These are for qwerty,
I mean. But I kind of just like 'x x' for M-x, easy to remember in reference to the 'actual' emacs command of M-x. Emacs undo is 'C-x u'. I resist making it 'y', or even, having a single-key for this. Would 'x u' suffice? One part of this thought is that I can also map all of the 'C-x' bindings, similarly. Of course, C-x is a prefix key, and it uses a keymap etc. The idea here is to consider using some of the more general keymaps. There is always the possibility of debating every decision, and reinventing everything, or reinventing it again, in this case. But I note, that ctl-x map key map is a full keymap, not a sparse keymap. That is, it has an entry that is a char-table. This is a compact way to record lots of bindings.

Actually, I'm following this idea:

';; x is for ctl-x-map'

http://ergoemacs.org/emacs/emacs_keybinding_redesign_2.html

For example, this means I can type 'x 2' to split this window, and type 'x 1' to close the other windows. I would love to not use '4' to split this window, because I have an objection to shadowing any of the number keys. Also not '3' to close the other windows.

I admit that I'm feeling cavalier about just using ESC to go back to command mode. Perhaps I may regress to using vim keybindings.

I also think it interesting that there is, in qwerty, a set of four keys for deleting: w, e, r, and d. By contrast, there is only one 'copy' (which is 'c', on qwerty).

w: xah-shrink-whitespaces
e: delete-back-word
r: delete-forward-word
d: delete-back-char

I'll convert to dvorak:
,: xah-shrink-whitespaces
.: delete-back-word
p: delete-forward-word
e: delete-back-char
I notice that there are lots of ways to 'delete', and wonder if there could be one 'delete' key, which takes arguments, especially as you also need to select, for copying and cutting. Perhaps I will learn to appreciate 'xah-shrink-whitespaces' as a special case, though my inclination off the cuff, is to bind it to 'x DEL' rather than giving it a one-stroke keybinding.

And, I notice this:

(defun xah-delete-current-text-block ()
  "Delete the current text block or selection, and copy to `kill-ring'.

So that's not actually 'delete'. It's 'cut'. And in dvorak, this is 'i'. Or, 'g' in qwerty. This is a fifth delete key, actually, or at least, it's not the 'cut' key, which is 'q' in dvorak, and is 'xah-cut-line-or-region'.

http://ergoemacs.org/misc/ergoemacs_vi_mode.html

Well, but what is the difference between 'i', or xah-delete-current-text-block, and 'q', or, xah-cut-line-or-region?

(defun xah-delete-current-text-block ()
  "Delete the current text block or selection, and copy to `kill-ring'.
A “block” is text between blank lines.

versus:

(defun xah-cut-line-or-region ()
  "Cut current line, or text selection.
When `universal-argument' is called first, cut whole buffer (respects `narrow-to-region').

These seem redundant, though I don't think it entirely probable that they work 'the same'..

@DanLanglois
Copy link
Contributor Author

DanLanglois commented Mar 17, 2019

I also notice the 'goto()' key, which is 'z' in dvorak. It calls xah-goto-matching-bracket.

(defun xah-goto-matching-bracket ()
  "Move cursor to the matching bracket.
If cursor is not on a bracket, call `backward-up-list'.
The list of brackets to jump to is defined by `xah-left-brackets' and `xah-right-brackets'.

Well, I am thinking about 'goto', here. Here, I might put in a prefix-command. Maybe for a goto-line, or a find-tag. I recall M-g M-g (which is the default binding of the goto-line function). And Emacs will prompt you for the number of the line and go to that line. But also, you can do this faster by invoking goto-line with a numeric argument that is the line's number. For example, C-u 286 M-g M-g will jump to line number 286 in the current buffer. Also, M-. (find-tag) is the command to find the definition of a specified tag. But if we have 'z' as a 'goto', then what about 'z .'.

Swell, but if I think of 'goto' as a prefix command, then what about 'Move cursor to the matching bracket'? I am intrigued, but I also remember seeing somewhere a xah-forward-right-bracket and a xah-backward-left-bracket. Yes, they're right here -- in dvorak, these are 'v' and 'm'. Sort of a 'beginning-of-expression', and an 'end-of-expression'. With those represented, does there really also have to be a 'move cursor to the matching bracket'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant