Coder Social home page Coder Social logo

keyadvice.el's Introduction

keyadvice.el

This package provides a functionality similar to "advice" package (defadvice) but for key bindings. You can advice any key binding to run your own code before or after the original action. This is useful if you want to run some conditional code together with the original (whatever that might be) binding. The original binding is a binding this key would normally invoke.

Inside the forms you provide to the macro you can use a special value "keyadvice-do-it" that will be replaced with code that will call the original function.

Interface

The advices will only be enabled if keyadvice-mode is enabled in current buffer. You can also use keyadvice-global-mode to enable keyadvice-mode globally in all buffers (recommended).

To add a key binding advice use:

(keyadvice-add-advice binding &rest forms)

(removing/temporary disabling etc. will come later/on demand :)

Examples

If you use AUCTeX (if you don't you should) there's a special minor mode called LaTeX-math-mode that provides many special key bindings for inserting mathematics. The most "famous" key binding is "`" command which takes additional letter(s) and expand them into LaTeX macros. For example "` a" inserts \alpha in the buffer.

However, entering the LaTeX-math-mode manually each time is annoying. You can advice the ` binding to automatically check if the point is inside math enviroment and then execute the apropriate expansion. Otherwise, it should call the function that would be normally bound to `.

(keyadvice-add-advice (kbd "`")
  (if (and (eq major-mode 'latex-mode) (texmathp))
      (let* ((events (let ((overriding-local-map LaTeX-math-keymap))
                       (read-key-sequence "math: ")))
             (binding (lookup-key LaTeX-math-keymap events)))
        (call-interactively binding))
    keyadvice-do-it)) ;; special value expands to the original function call

keyadvice.el's People

Contributors

fuco1 avatar

Stargazers

Juri Hahn avatar Priyadarshan avatar Alex J. Grede avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

emacsmirror

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.