Giter Site home page Giter Site logo

Comments (5)

trev-dev avatar trev-dev commented on July 21, 2024 1

Knowing how to do it without it being built into god-mode is just as good in my opinion. I was thinking that someone like yourself might have some idea of how to do it.

I prefer to explicitly call a function that disables god mode and performs some related key-command. However, I think that advice tip is huge. I don't yet understand what advice actually does, but I'm going to dig into it.

Thanks @darth10

from god-mode.

trev-dev avatar trev-dev commented on July 21, 2024 1

That advice tip is super cool. I was able to create a silly "insert-ahead" keybind for forward/backward motions that let me move 1 character in the correct direction and exit god-local-mode. This makes spamming forward-word/symbol or backward-word/symbol more useful because sometimes where I want to be is just after some word/symbol separator.

It looks like the :around option for advice-add is probably the way to go for these M-RET functions, as I would be able to capture the called function and execute it inside the body of my advice function 😎

from god-mode.

darth10 avatar darth10 commented on July 21, 2024 1

No worries!

I can also suggest a few improvements to your ELisp snippet there:

(defun disable-god-mode (&rest _)
  (god-local-mode -1))

(advice-add 'org-meta-return :after #'disable-god-mode
            (function 'god/insert-after-org-meta-return))

(advice-add 'org-insert-todo-heading :after #'disable-god-mode
            (function 'god/insert-after-org-new-heading))

from god-mode.

darth10 avatar darth10 commented on July 21, 2024

That's an interesting idea, but this sounds more like user-level customisation to me.

There are a couple ways to achieve this:

  1. Use god-execute-with-current-bindings, which enables God mode for a single command, executes the command for a key binding, and disables God mode. If God mode is already enabled, then god-execute-with-current-bindings simply executes a command and disables God mode.
  2. Use advice functions. For example:
    (defun disable-god-mode (&rest _)
      (god-local-mode -1))
    
    (advice-add 'end-of-line :after #'disable-god-mode)
    (advice-add 'back-to-indentation :after #'disable-god-mode)
    (advice-add 'org-insert-todo-heading :after #'disable-god-mode)
    ;; ...
    A potential problem that I see with this approach is that common functions like end-of-line may be called by other packages, which would disable God mode without the user intending to do so.

Does that help @trev-dev?

from god-mode.

trev-dev avatar trev-dev commented on July 21, 2024

Meh, rather than try to hook into "Meta Return" I took the simpler route with advice as well.

(advice-add 'org-meta-return :after
            #'(lambda (&rest args) (god-local-mode -1))
            '(( name . "god/insert-after-org-meta-return")))

(advice-add 'org-insert-todo-heading :after
            #'(lambda (&rest args) (god-local-mode -1))
            '(( name . "god/insert-after-org-new-heading")))

This works great. Thanks again for the tip @darth10

from god-mode.

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.