ergoemacs / ergoemacs-mode

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

Faster, more robust, less featured version #505

Closed wlandry closed 3 years ago

wlandry commented 3 years ago

I have a branch of ergoemacs at

https://github.com/wlandry/ergoemacs-mode

that fixes a number of problems I was having with specdl, timeouts, and generally slow startup. It was bad enough that mu4e was constantly breaking. These fixes make it usable for everyday use, and I have been using it for several months without problems.

The catch is that I have radically simplified the scope of ergoemacs. It no longer supports fly-keys, cua, gradual ergoemacs, and probably some other things I do not remember. So I do not know if you are interested in merging these changes, but I figured that I should ask.

wlandry commented 3 years ago

Removed C-h '

That is unfortunate. I find it really useful to have a way to show all of the current key bindings, because I definitely do not remember all of them. For new users, it is even more important. Is there something I could do to keep it working?

Also added the M- keys for term.

That is awesome. I was shadowing the control keys before, but this is much better. Now I can use nano in term. Thanks.

wlandry commented 3 years ago

What is the proper way to override a M- key? For me, I want to globally set M-> to xref-find-references. If I set it with

(global-set-key (kbd "M->") 'xref-find-references)

it gets overridden by ergoemacs, which undefines it.

mattfidler commented 3 years ago

To override ergoemacs-mode keybinding you can use:

(define-key ergoemacs-user-keymap (kbd "M->") 'xref-find-references)

I haven't created a special keymap for user bindings when a region is active.

To use changes to the global map can be maintained, but is harder to maintain and slows the startup. It was removed.

mattfidler commented 3 years ago

That is unfortunate. I find it really useful to have a way to show all of the current key bindings, because I definitely do not remember all of them. For new users, it is even more important. Is there something I could do to keep it working?

I agree, but am a bit pressed for time. If you want, you can look at ergoemacs-theme-engine. Most the code to generate an image is still there. I just tested it and it doens't work.

Once that is done, you can make a composed keymap and describe the keys easily enough to create a function that describes the keymap.

mattfidler commented 3 years ago

it gets overridden by ergoemacs, which undefines it.

FYI, it is not really undefined, it simply binds it to the undefined function so it seems to be undefined...

wlandry commented 3 years ago

To override ergoemacs-mode keybinding you can use:

(define-key ergoemacs-user-keymap (kbd "M->") 'xref-find-references)

That works. I think that is enough as long as it is documented somewhere.

That is unfortunate. I find it really useful to have a way to show all of the current key bindings, because I definitely do not remember all of them. For new users, it is even more important. Is there something I could do to keep it working?

I agree, but am a bit pressed for time. If you want, you can look at ergoemacs-theme-engine. Most the code to generate an image is still there. I just tested it and it doens't work.

No promises, but I will look into it.

wlandry commented 3 years ago

Running gnus, it got rid of the C-k binding for gnus-summary-kill-same-subject. Did you intend to override local mode C- bindings? It left C-k unbound.

mattfidler commented 3 years ago

Indeed this is "meant" to happen. C-k is kill line in emacs so it should be bound in the proper place in ergoemacs-mode.

This is the consequence of not calculating each active keymap...

mattfidler commented 3 years ago

Of course you can calculate these bindings with ergoemacs-calculate-keybindings-for-both-themes:

(ergoemacs-save-key-state 'gnus-mode-map (if (string-equal ergoemacs-theme "reduction")
  (progn
    (ergoemacs-define-key gnus-mode-map (kbd "M-d") 'scroll-down-command)
    (ergoemacs-define-key gnus-mode-map (kbd "DEL") 'scroll-down-command))
  (ergoemacs-define-key gnus-mode-map (kbd "M-d") 'scroll-down-command)
  (ergoemacs-define-key gnus-mode-map (kbd "DEL") 'scroll-down-command)))

;; For gnus summary
(ergoemacs-save-key-state 'gnus-summary-mode-map (if (string-equal ergoemacs-theme "reduction")
  (progn
    (ergoemacs-define-key gnus-summary-mode-map (kbd "M-d") 'gnus-summary-prev-page)
    (ergoemacs-define-key gnus-summary-mode-map (kbd "DEL") 'gnus-summary-prev-page)
    (ergoemacs-define-key gnus-summary-mode-map (kbd "<delete>") 'gnus-summary-enter-digest-group)
    (ergoemacs-define-key gnus-summary-mode-map (kbd "M-f") 'gnus-summary-enter-digest-group)
    (ergoemacs-define-key gnus-summary-mode-map (kbd "<M-left>") 'gnus-summary-prev-thread)
    (ergoemacs-define-key gnus-summary-mode-map (kbd "M-J") 'gnus-summary-prev-thread)
    (ergoemacs-define-key gnus-summary-mode-map (kbd "<M-left>") 'gnus-summary-next-thread)
    (ergoemacs-define-key gnus-summary-mode-map (kbd "M-J") 'gnus-summary-next-thread)
    (ergoemacs-define-key gnus-summary-mode-map (kbd "C-M-d") 'gnus-summary-show-thread)
    (ergoemacs-define-key gnus-summary-mode-map (kbd "M-g") 'gnus-summary-kill-same-subject)
    (ergoemacs-define-key gnus-summary-mode-map (kbd "<deleteline>") 'gnus-summary-kill-same-subject))
  (ergoemacs-define-key gnus-summary-mode-map (kbd "M-d") 'gnus-summary-prev-page)
  (ergoemacs-define-key gnus-summary-mode-map (kbd "DEL") 'gnus-summary-prev-page)
  (ergoemacs-define-key gnus-summary-mode-map (kbd "<delete>") 'gnus-summary-enter-digest-group)
  (ergoemacs-define-key gnus-summary-mode-map (kbd "M-f") 'gnus-summary-enter-digest-group)
  (ergoemacs-define-key gnus-summary-mode-map (kbd "<M-left>") 'gnus-summary-prev-thread)
  (ergoemacs-define-key gnus-summary-mode-map (kbd "M-J") 'gnus-summary-prev-thread)
  (ergoemacs-define-key gnus-summary-mode-map (kbd "<M-left>") 'gnus-summary-next-thread)
  (ergoemacs-define-key gnus-summary-mode-map (kbd "M-J") 'gnus-summary-next-thread)
  (ergoemacs-define-key gnus-summary-mode-map (kbd "C-M-d") 'gnus-summary-show-thread)
  (ergoemacs-define-key gnus-summary-mode-map (kbd "M-g") 'gnus-summary-kill-same-subject)
  (ergoemacs-define-key gnus-summary-mode-map (kbd "<deleteline>") 'gnus-summary-kill-same-subject)))
mattfidler commented 3 years ago

There are more too:

(ergoemacs-save-key-state 'gnus-article-mode-map (if (string-equal ergoemacs-theme "reduction")
  (progn
    (ergoemacs-define-key gnus-article-mode-map (kbd "M-d") 'gnus-article-goto-prev-page)
    (ergoemacs-define-key gnus-article-mode-map (kbd "DEL") 'gnus-article-goto-prev-page)
    (ergoemacs-define-key gnus-article-mode-map (kbd "<delete>") 'gnus-article-read-summary-keys)
    (ergoemacs-define-key gnus-article-mode-map (kbd "M-f") 'gnus-article-read-summary-keys)
    (ergoemacs-define-key gnus-article-mode-map (kbd "M-t") 'backward-button))
  (ergoemacs-define-key gnus-article-mode-map (kbd "M-d") 'gnus-article-goto-prev-page)
  (ergoemacs-define-key gnus-article-mode-map (kbd "DEL") 'gnus-article-goto-prev-page)
  (ergoemacs-define-key gnus-article-mode-map (kbd "<delete>") 'gnus-article-read-summary-keys)
  (ergoemacs-define-key gnus-article-mode-map (kbd "M-f") 'gnus-article-read-summary-keys)
  (ergoemacs-define-key gnus-article-mode-map (kbd "M-t") 'backward-button)))
mattfidler commented 3 years ago

Basically, since gnus is a large package, every keymap it binds would likely need some work-around keymap.

mattfidler commented 3 years ago
(ergoemacs-save-key-state 'gnus-bookmark-bmenu-mode-map (if (string-equal ergoemacs-theme "reduction")
  (progn
    (ergoemacs-define-key gnus-bookmark-bmenu-mode-map (kbd "M-d") 'gnus-bookmark-bmenu-backup-unmark)
    (ergoemacs-define-key gnus-bookmark-bmenu-mode-map (kbd "DEL") 'gnus-bookmark-bmenu-backup-unmark)
    (ergoemacs-define-key gnus-bookmark-bmenu-mode-map (kbd "<delete>") 'gnus-bookmark-bmenu-delete-backwards)
    (ergoemacs-define-key gnus-bookmark-bmenu-mode-map (kbd "M-f") 'gnus-bookmark-bmenu-delete-backwards))
  (ergoemacs-define-key gnus-bookmark-bmenu-mode-map (kbd "M-d") 'gnus-bookmark-bmenu-backup-unmark)
  (ergoemacs-define-key gnus-bookmark-bmenu-mode-map (kbd "DEL") 'gnus-bookmark-bmenu-backup-unmark)
  (ergoemacs-define-key gnus-bookmark-bmenu-mode-map (kbd "<delete>") 'gnus-bookmark-bmenu-delete-backwards)
  (ergoemacs-define-key gnus-bookmark-bmenu-mode-map (kbd "M-f") 'gnus-bookmark-bmenu-delete-backwards)))
mattfidler commented 3 years ago

Probably this would be written over too. Another option is to send emacs keys and shuffle which keymaps are on similar to what the cua mode does for the C-c keys

wlandry commented 3 years ago

I think it would be good to have a decent binding for gnus, since it is widely used. I use gnus regularly, so I will look into it. One thing I do not understand is why you have separate code for the reduction theme. The code looks identical to me. I also see this duplication in ergoemacs-install-comint-bindings. Can I consolidate things, or is there something I am missing?

mattfidler commented 3 years ago

These are autogenerated. You can reduce it if you wish, there should be no consequence if they are duplicated.

There is an interactive function for calculating keybindings called ergoemacs-calculate-keybindings-for-both-themes. If you select a keymap it will put in the ergoemacs-mode keybindings into that map.

mattfidler commented 3 years ago

However, the major mode keybindings for comint-mode are not being respected either. So the inheritance is problematic right now.

mattfidler commented 3 years ago

keymap lookup is:

(or (if overriding-terminal-local-map
        (find-in overriding-terminal-local-map))
    (if overriding-local-map
        (find-in overriding-local-map)
      (or (find-in (get-char-property (point) 'keymap))
          (find-in-any emulation-mode-map-alists)
          (find-in-any minor-mode-overriding-map-alist)
          (find-in-any minor-mode-map-alist)
          (if (get-text-property (point) 'local-map)
              (find-in (get-char-property (point) 'local-map))
            (find-in (current-local-map)))))
    (find-in (current-global-map)))

https://www.gnu.org/software/emacs/manual/html_mono/elisp.html#Searching-Keymaps

mattfidler commented 3 years ago

So, anything that adds a keymap property, or in the overriding-local-map or overriding-terminal-local-map will override the ergoemacs-mode keybindings.

mattfidler commented 3 years ago

This is why `isearch mode keys need to be changed, but comit-mode keys do not need to be changed.

wlandry commented 3 years ago

I found another issue. I do an incremental search forward, then decide to search backward. The reverse search does not contain the search string that I was using. Specifically, using colemak bindings, I type

M-o is

This highlights all occurences of is in the buffer. Repeating M-o goes to the next result. Now I decide to reverse the search. I type M-O and is should already be filled out as the search string. This worked in my version, but something broke it in your version.

mattfidler commented 3 years ago

Hm. It works for me....

mattfidler commented 3 years ago

Perhaps 500a2eb7c4dd704f6bd69c115f6817a48440f719 for you?

wlandry commented 3 years ago

That did not fix it for me. I am running with -q -l emacs_test_startup.el, where that elisp file is

(add-to-list 'load-path "/home/boo/random_stuff/ergoemacs-mode_main/")
(require 'ergoemacs-mode)
(setq ergoemacs-keyboard-layout "colemak")
(ergoemacs-mode)

I see the same problem with qwerty.

mattfidler commented 3 years ago

The keymap was generated from colemak. In colemak, the M-O is the key so it is a bug in the key lookup for the standard theme. I corrected it manually, but I am thinking this would not actually work for the isearch in the terminal unless the M-O is updated there too. Something more general.

mattfidler commented 2 years ago

The M-O for isearch backward should work for you now. Also C-h b should show the ergoemacs->emacs keybindings when passing emacs keys.

I'm unsure where else they should be displayed.

wlandry commented 2 years ago

M-O works for backwards search. Thanks. C-h b still does not show that M-d will eventually end up calling gnus-summary-kill-same-subject. It looks like it will delete the line, which is definitely different from killing everything with the same subject. I still think that a direct mapping would be better.

mattfidler commented 2 years ago

C-h b still does not show that M-d will eventually end up calling gnus-summary-kill-same-subject. It looks like it will delete the line, which is definitely different from killing everything with the same subject.

I tested with changes in the global-map. Now I tested changes in the major mode map. Now they display for me.

I also added a function to pull the "correct" function for describe-key

I still think that a direct mapping would be better.

This reamap still be turned off with ergoemacs-mode-send-emacs-keys. If you want to get back the C-k, you can remove the undefined references by turning off ergoemacs-mode-unbind-emacs-keys.

I do have to say, it is complicated to overwrite ergoemacs-mode keys where they stand based on direct mapping.

mattfidler commented 2 years ago

Still the key map lookup is broken for M-O

wlandry commented 2 years ago

Everything seems to work for me, including the binding for M-O. I am still concerned about too much magic, but I can live with it. Thanks.

mattfidler commented 2 years ago

Great.

If it gets too much, I have allowed the variables above, and maybe you can figure out some solution to allow keymaps.

Matt

mattfidler commented 2 years ago

@wlandry

Can you reach out to me via email so I can get your information for signing the FSF paperwork?

I just reached out to Stefan Monnier today about the agreement.