Giter Club home page Giter Club logo

acme-mouse-3's Introduction

acme-mouse-3.el

An Emacs package which lets you evaluate (run) Elisp code using the right mouse button, inspired by the “Execute text” command in Rob Pike’s Acme editor.

Usage

eval-region-or-word is the function that does the evaluation.

By default, it’s bound to <mouse-3>, which corresponds to the right mouse button in Emacs, as opposed to <mouse-2> (middle mouse) like it is in Acme because… I wanted it like that?

To be fair, nowadays, more computers have only <mouse-1> and <mouse-3>, for example laptops, which makes all the sense. I suppose three-button mice were more common back then.

Customising

If you want, you can bind this function to a custom keyboard shortcut.

For example, to bind it to the key combination C-c e, you can add the following code to your init.el:

(global-set-key (kbd "C-c e") 'eval-region-or-word)

With this, in addition to the right mouse button, you can now use a keyboard shortcut to use the function.

Just keep in mind acme-mouse-3 was designed specifically for the mouse, and might break if the mouse isn’t in an Emacs pane.

How it works

  • First of all, we define eval-region-or-word.
(defun eval-region-or-word ()
  "Evaluate the current region or word under the mouse cursor."
  (interactive)
  • Next, we create a let-binding and define region, whose value depends on whether or not an active region (selection) is present.
  • A let-binding, in the context of Elisp, allows you to create temporary variables with specific values within a local block of code.
  • If there’s an active region, we set the region variable to that.
(let ((region (if (region-active-p)
                  (buffer-substring-no-properties (region-beginning) (region-end))
  • Otherwise, we set the text cursor to where the mouse pointer is and temporarily modify the syntax table to include hyphens as part of words.
  • After that, region is set to the word the text cursor was moved to/is under, effectively setting region to the word under the mouse pointer.
(progn
  (mouse-set-point last-nonmenu-event)
  (with-syntax-table (copy-syntax-table (syntax-table))
    (modify-syntax-entry ?- "w")
    (thing-at-point 'word)))))) 
  • After region is set, we check if ( and ) are the prefix and suffix of region respectively.
  • If not, we add that, so that it’s a legitimate Lisp expression.
  • Finally, we read the value of region and evaluate it, which ends the function.
(when region
  (unless (string-prefix-p "(" region)
    (setq region (concat "(" region)))
  (unless (string-suffix-p ")" region)
    (setq region (concat region ")")))
  (eval (read region))
)

Is this package useful?

Okay, I don’t quite know how to say this tactfully, but it’s possible that I slightly exaggerated the useful nature of the package.

Is it a very, very neat package?

To be certain it is! It’s an extremely neat package!

I don’t want anyone to say that it isn’t an astonishingly neat package - it is!

Is it useful?

Well that sort of depends on your definition of usefulness.

From one perspective the useful is merely philosophical in nature. It’s more of a-

github.com/akrito/acme-mouse

Okay, well good for you, you found the more popular and useful Acme Emacs mouse package.

You found me out, user.

I’m a liar and a cheat and you’re so clever.

Look, I think the issue here is just that you’re unusually fascinated by tried and tested packages.

What normal person actually wants to use a program entirely for its usefulness?

I figured the package was as useful as anyone would actually need!

Don’t you put this on me! Maybe you’re the problem!

sigh Look… things got a little heated there.

I think we both said some things we didn’t mean.

Why don’t we just put all this behind us and agree to just call the package mostly-useful.

If that works for you, then go ahead and download the package and add it to your init.el, and we can move on.

I’ll just be over here when you are ready.

License

This package is licensed under the GNU General Public License v3 or later.

Free Software, hell yeah!

acme-mouse-3's People

Contributors

aeriavelocity avatar

Watchers

 avatar

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.