GithubHelp home page GithubHelp logo

rswgnu / rsw-elisp Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 0.0 70 KB

Interactively evaluate regions, preceding variable definitions and quoted sexpressions

License: GNU General Public License v3.0

Emacs Lisp 100.00%

rsw-elisp's Introduction

rsw-elisp - Interactively evaluate regions, preceding variable definitions and quoted sexpressions

This code improves and replaces the GNU Emacs commands that interactively evaluate Emacs Lisp expressions. The new commands replace standard key bindings and are all prefixed with rsw-elisp-. They work the same way as the old commands when called non-interactively; only the interactive behavior should be different, as described below.

To set up to use this every Emacs session, first install this package with an Emacs package manager and then add the following to your Emacs initialization file:

(require 'rsw-elisp)
(rsw-elisp-enable)

Or you can test it out the remapped key bindings of all of the interactive Emacs Lisp evaluation commands and a few minibuffer helper commands, with:

M-x rsw-elisp-enable RET

To return to the standard key bindings, use:

M-x rsw-elisp-disable RET

To toggle this on and off, use:

M-x rsw-elisp-toggle RET

Programmatically, to see whether it is enabled or not, use:

(rsw-elisp-p)

The commands and key bindings herein provide 5 new features for interactive Emacs Lisp evaluation:

  1. Evaluating Quoted Expressions: C-x C-e (eval-last-expression) on a regularly quoted sexpression doesn't show you anything different than what you see on screen already. You really want to see the value of the unquoted sexpression and now you can. C-x C-e (rsw-elisp-eval-last-expression) and M-: (rsw-elisp-eval-expression) remove any regular outer quotes from sexpressions and show you the value. For example, 'emacs-version interactively yields "26.0.50".

    This is for programmers who already understand how quoting works and don't need to see the same expression fed back to them. For times where you really need to see the quoted form, use a backquote ` or a backquote followed by a regular quote '.

  2. Evaluating Function Symbols: When interactively evaluating a symbol, Emacs returns only the symbol's value, giving an unbound error if it is not defined. But if it is a function symbol in such a case, you typically want to see its function binding, so these functions return that when the symbol is bound as a function (or a macro) but not a variable.

  3. Redefining Variables: Interactively calling eval-last-expression with point after a previously defined variable definition does not reset its value in Emacs, though clearly the only reason to do this is to redefine the variable. Although eval-defun does do this, there is no reason to have to use a different key binding than you would to interactively evaluate other expressions. C-x C-e (rsw-elisp-eval-last-expression) resolves this.

  4. Default Expressions to Evaluate: When using M-: bound to (rsw-elisp-eval-expression), if a region is active, the leading expression in the region is used as the default expression to evaluate and included in the prompt. Otherwise, if called with point in an Emacs Lisp mode listed in rsw-elisp-modes and not on a whitespace character, then the expression around point is used as the default.

  5. Editing Default Expressions: If you ever want to edit the default, use M-y (rsw-elisp-yank-pop) to yank it into the editable portion of the minibuffer, any time other than after a yank command. (M-y still performs its normal yank-pop function after a C-y yank command). If you yank in a large expression by mistake, press C-d or DELETE FORWARD when at the end of the minibuffer to erase its entire contents. If you prefer these helper keys not be bound, after the call to:

    (rsw-elisp-enable)
    

    add:

    (setq rsw-elisp-helper-keys nil)
    

rsw-elisp's People

Contributors

rswgnu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rsw-elisp's Issues

Compatibility with eval-sexp-fu.el

eval-sexp-fu.el defines a minor mode that flashes evaluated s-expressions. It's a great visual helper, and is part of spacemacs' default setup. It'd be great if this package could include a similar flashing mechanism.

Using eval-sexp-fu is probably easiest, but since the code is on emacswiki and was last changed in 2013 it might just be easier to do your own thing (using pulse worked quite well in treemacs).

Void function error when evaluating require form

Trying to execute a (require 'foo) form nets me the following stacktrace:

Debugger entered--Lisp error: (void-function eval-expression-get-print-arguments)
  eval-expression-get-print-arguments(nil)
  rsw-elisp-internal-eval-last-sexp(nil 1)
  rsw-elisp-eval-last-sexp-or-def(nil 1)
  rsw-elisp-eval-last-sexp(nil 1)
  funcall-interactively(rsw-elisp-eval-last-sexp nil 1)
  call-interactively(rsw-elisp-eval-last-sexp record nil)
  command-execute(rsw-elisp-eval-last-sexp record)
  helm-M-x(nil #("rsw-elisp-eval-last-sexp" 0 24 (match-part "rsw-elisp-eval-last-sexp")))
  funcall-interactively(helm-M-x nil #("rsw-elisp-eval-last-sexp" 0 24 (match-part "rsw-elisp-eval-last-sexp")))
  call-interactively(helm-M-x nil nil)
  command-execute(helm-M-x)

Looks like eval-expression-get-print-arguments is not availabe in emacs 25. The fuction is fairly short so you can define it yourself for <26.

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.