Giter VIP home page Giter VIP logo

Comments (6)

noctuid avatar noctuid commented on June 29, 2024

Well with (setq general-default-keymaps 'evil-normal-state-map)

(general-define-key "U" 'redo)
;; is the equivalent of 
(general-define-key :keymaps 'evil-normal-state-map "U" 'redo)
;; or  
(general-nmap "U" 'redo)

I don't think the problem you're describing should be happening. Generally, you wouldn't (need to) define keys for states in the global map (maybe read this part of the readme if you haven't already).

Then U is undefined in dired. However, if I define :states 'normal instead of using general-default-keymaps, all my bindings are available like I want.

Does this happen for other modes (I've never experienced this)? Does this also happen if you do the following?

(define-key evil-normal-state-map "U" 'undo)
(evil-define-key 'normal dired-mode-map
  <mappings>)

To clarify, you're saying that U is completely unbound (and not bound to dired-unmark-all-marks)? And this only happens if you also use general-evil-define-key for the mode?

from general.el.

auwsmit avatar auwsmit commented on June 29, 2024

To clarify, you're saying that U is completely unbound (and not bound to dired-unmark-all-marks)? And this only happens if you also use general-evil-define-key for the mode?

Sorry, that was bad wording on my part. By "U is undefined in dired" I meant that U is bound to dired-unmark-all-marks instead of my custom mapping for normal-state.

However after doing further testing, I think that this was happening because of evil-make-overriding-map. It's applied to dired-mode-map (via evil-integration.el) and occur-mode-map (via my config), so they simply had higher precedence than my other mappings.

But now I'm wondering, is there a difference between

(evil-define-key :states 'normal "U" 'undo)

and

(evil-define-key :keymaps 'evil-normal-state-map "U" 'undo)

Because only the former would allow me to use U in Dired despite evil-make-overriding-map.

from general.el.

noctuid avatar noctuid commented on June 29, 2024

However after doing further testing, I think that this was happening because of evil-make-overriding-map

Yeah that was my guess. I talk a little about ways around this in the last paragraph here if you don't want dired-mode-map to have a higher precedence. The best way is to prevent the code in integration.el from being run. Defining in the global-map for normal state also gets around it.

As for the difference between states and keymaps here, evil-normal-state-map is a global keymap. With something like (evil-define-key 'normal dired-mode-map ...), evil-get-auxiliary-map is used to create a new keymap. (general-define-key :states 'normal ...) is the same as (evil-define-key 'normal (current-global-map) ...). The global evil-normal-state-map is what is overriden in integration.el, so keys bound in the global-map with evil-define-key are not affected.

You can keep using this as a solution to prevent your keys from being overridden if you want to. It may be a good solution; I'm just not sure if there might be downsides since I haven't tried this out myself. One thing to note is that this will only work for keys you define yourself (keys you leave the same will still be overridden). If you'd rather not use general-default-states and like the general-nmap-like commands, I could add an option or argument to have them be created to define in the global-map for a state instead.

from general.el.

auwsmit avatar auwsmit commented on June 29, 2024

The best way is to prevent the code in integration.el from being run.

I just advise it [evil-make-overriding-map] into non-existences (with :around (lambda (orig-func))).

Could you elaborate more on how to this? I can't really figure out the documentation for add-advice/add-function.

I could add an option or argument to have them be created to define in the global-map for a state instead.

That would be pretty cool to have as an option and I'd use it. I do like the shorter names and their similarity to Vim.

from general.el.

noctuid avatar noctuid commented on June 29, 2024

To prevent a function from ever being run, you can advise it before it is created like this:

(advice-add 'evil-make-overriding-map
            :around (defun my-kill-overriding-maps (_ &rest _)))

The :around keyword will cause the function you provide to replace the function you are advising. The original function and arguments are passed in as arguments to the new function. In this case, the original function is just ignored and nothing ever happens when it is called.

If you want to use evil-make-overriding-map yourself afterwards, you will need to get rid of the advice (I'd recommend doing it just after loading evil):

(advice-remove 'evil-make-overriding-map #'my-kill-overriding-maps)

That would be pretty cool to have as an option and I'd use it.

Okay, I've made a new issue for it. Would you prefer that it be an argument when creating them (e.g. (general-evil-setup _ <arg to decide>)) or something that could be toggled after creating them (either with a global variable or with a keyword argument to general-nmap)? If you don't have a preference, I think I'll implement it as a global variable.

from general.el.

auwsmit avatar auwsmit commented on June 29, 2024

Hooray, I feel like I have total control over my bindings with evil-make-overriding-map disabled!

(e.g. (general-evil-setup _ ))

This seems pretty sensible and fits as an extra option like SHORT-NAMES.

Thanks for all the info and help. Evil + general + the helpful community is really making Emacs into a perfect editor (for me) that I can easily configure and adapt.

from general.el.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.