Giter VIP home page Giter VIP logo

emacs-anywhere's Introduction

Inspired by cknadler/vim-anywhere

Emacs Anywhere provides configurable automation and hooks containing window info, so you can bust moves anywhere in a quick, customizable fashion.

Table of Contents

Install

OS X

curl -fsSL https://raw.github.com/zachcurry/emacs-anywhere/master/install | bash

Open System Preferences and navigate to keyboard > shortcuts > Services. Check the box beside "Emacs Anywhere", click "Add Shortcut" and key a shortcut.

Linux

In order to use Emacs Anywhere, you must use Xorg as your window manager. You can switch your window manager in Ubuntu by going to the login screen, clicking the cog icon, and selecting Xorg.

dependencies

Install these dependencies as needed

  • xclip
  • xdotool
  • xwininfo
sudo apt-get install <dependency>

Install

curl -fsSL https://raw.github.com/zachcurry/emacs-anywhere/master/install | bash

Create a keyboard shortcut to run ~/.emacs_anywhere/bin/run.

Windows

TBD

Usage

Try It

  1. Make sure your Emacs server is running. You can start the server like this
emacs --daemon
  1. Focus an application window's text input. A text area in your browser will do.
  2. Key the keyboard shortcut you've chosen for Emacs Anywhere
  3. Write some text
  4. Delete the frame (C-x 5 0, or :q if you use evil-mode). Emacs Anywhere will copy the text from the buffer "*Emacs Anywhere*" to clipboard, delete the buffer, switch focus to the window from step two and paste the buffers content into the text input.

Environment

The EA_EDITOR environment variable can be used to override the way emacsclient is run. For example, you could put the following statement into your .bash_profile.

export EA_EDITOR='emacsclient -a "" -c'

With the environment variable set, the invocation will look like this under the hood

emacsclient -a "" -c -e <elisp code>

You can prefix emacsclient with it's path if Emacs Anywhere can't find it in your PATH environment variable.

Commands

Command Description
toggle-ea If toggled to the "off" state, Emacs Anywhere will do nothing when the frame is deleted.

Variables

Variable Description
ea-on Boolean where t and nil denote the "on" and "off** states of Emacs Anywhere, respectively. The default value is t
ea-copy If true, the "*Emacs Anywhere*" buffer will be copied to clipboard. The default value is t
ea-paste If true, Emacs Anywhere will paste to the window from which it was launched. The default value is t
ea-app-name The name of the application process for the window from which Emacs Anywhere was launched.
ea-window-title The title of the window from which Emacs Anywhere was launched.
ea-x The x-coordinate of the upper-left corner of the window from which Emacs Anywhere was launched.
ea-y The y-coordinate of the upper-left corner of the window from which Emacs Anywhere was launched.
ea-width The width of the window from which Emacs Anywhere was launched.
ea-height The height of the window from which Emacs Anywhere was launched.

Note: In OS X the window title, position and size information is only available if the application is has accessiblity permissions enabled.

Hooks

Hook Function Signature Description
ea-popup-hook (app-name window-title x y w h) Functions run after an Emacs Anywhere session starts.

Examples

;; Define a function or use a lambda of the same signature
(defun popup-handler (app-name window-title x y w h)
  ;; do stuff
  )

;; Hook your function
(add-hook 'ea-popup-hook 'popup-handler)

In your hook function you can do things like set the major mode based on the application name or window title...

(defun github-conversation-p (window-title)
  (or (string-match-p "Pull Request" window-title)
      (string-match-p "Issue" window-title)
      ;; ...
      ))

(defun popup-handler (app-name window-title x y w h)
  ;; set major mode
  (cond
    ((github-conversation-p window-title) (gfm-mode))
    ;; ...
    (t (markdown-mode)) ; default major mode
    ))

...or set the frame size and position to fit the bottom 400px of the window...

(defun popup-handler (app-name window-title x y w h)
  (set-frame-position (selected-frame) x (+ y (- h 400)))
  (unless (zerop w)
    (set-frame-size (selected-frame) w 400 t))
  ;; ...
  )

...or configure automation settings

(defun popup-handler (app-name window-title x y w h)
  (when (equal app-name "Terminal")
    ;; Tell Emacs Anywhere not to paste if launched from Terminal
    (setq ea-paste nil))
  ;; ...
  )

Update

~/.emacs_anywhere/update

Uninstall


~/.emacs_anywhere/uninstall

Todo

  • Windows

Contributing

TBD

License

MIT

Copyright © 2018, Zach Curry, All rights reserved.

emacs-anywhere's People

Contributors

elimisteve avatar jacobmealey avatar novoid avatar pathouse avatar srid avatar syadegari avatar tecosaur avatar timdupontpxl avatar zachcurry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

emacs-anywhere's Issues

Edit text

I don't know what you think but, I've thought about whether it would be better if selected text (or text in a text field) should be pre-inserted in emacs or not. Another idea could be to provide a settings for emacs-everywhere to choose things like this.
The current alternative isn't that bad either, one must just select and copy the text, and then paste it on emacs, after it would be replaced because it was selected before insertion.

Paste not working when there is a physical key pressed

I bind delete-frame to hyper-space, because c-x 5 0 is too many keys to press. Sometimes I did not release hyper key quick enough, and the content is not pasted. I am looking for a way to let xdotool ignore the maybe pressed hyper key.

not working with ubuntu

I am unable to get this to work in Ubuntu. I can not install the dependencies xprop and xwininfo which may be the reason.
$ sudo apt-get install xprop
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package xprop

sudo apt-get install xwininfoReading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package xwininfo

Does not work with the freecodecamp editor

Runtime Environment

Issue

Emacs Anywhere works very well in all kinds of text fields, except for the https://learn.freecodecamp.org/ the editor. I tested on Google Chrome using both atomic-chrome and ghost-text. The extensions are able to connect with Emacs, but only part of the text in the field becomes available and my edits are not reflected on Emacs are not reflected in the browser.

Not working with the Emacs Mac Port?

As per the discussion at #8, I tried this with the Emacs Mac Port and it seems that nothing happens. There is a little gear icon in the menu bar for a moment, but then nothing happens and the gear icon disappears. Is there a log file somewhere which could give a clue as to what's going wrong?

new to OSX, tell EA to open on current space?

Hi again! been using EA for months on linux and lovin' it :)

Now at work have to use OSX and it works well. only issue is that emacs is always on space #1 and chrome on space #2. when i launch EA it takes me automatically to space #1 where EA opens.
Anyway to define the EA frame to open on the current space where it was launched from?

thx!!

Z

Would you recommend an especific keybinding (shortcut) on macOS?

Hi,

This project seems to be quite cool!

I am trying this on macOS. Would you recommend a specific keybinding (shortcut)? Are there some frequent ones?

I know keybindings are a bit subjective. But there is also common sense in the choice. And I am new to macOS. Hence, I am not familiar with the default choices and the "philosophy" of the UX.

Thanks

On invoking the shortcut, I receive an error popup reporting 'The action “Run Shell Script” encountered an error.'

On invoking the shortcut, I receive an error popup reporting 'The action “Run Shell Script” encountered an error.'

The popup has the options "OK" (dismissing the poup) and "Show Workflow", which opens "/Users/ree/Library/Services/", showing Emacs Anywhere.workflow. If I try to open it and run it in Automator, I get an error popup showing

The action “Run Shell Script” encountered an error.

161:177: execution error: System Events got an error: osascript is not allowed assistive access. (-25211)
52:64: execution error: System Events got an error: osascript is not allowed assistive access. (-1719)
emacsclient: could not get terminal name
emacsclient: error executing alternate editor """"

With only an "OK" button.

After some googling, I found that the osascript error had been experienced by people in other contexts. In particular, I reviewed this stack overflow issue: https://apple.stackexchange.com/questions/291574/osascript-is-not-allowed-assistive-access-1728

Following that, I tried giving the Emacs Anywhere.workflow file a checkmark in Security & Privacy > Allow the apps below to control your computer. It didn't make any difference.

Automatically pick major mode

I'm not sure what our options are but it would be super cool if I could execute this on say github comment box and the frame would pop up in gfm-mode automatically.

I think if we could somehow pass the window title (xwininfo can grab that) or some other properties to some callback/hook then we could configure this in our own emacs configs (because we are using the emacsclient here).

This package could come with some preconfigured setup that the user would just enable or they can create their own.

What do you think?

Errors when running install script on GNU/Linux

When I run the install script (through ./emacs_anywhere/install) on my system (Manjaro Linux), I get the following errors (before it says it was successfully installed anyways):

cp: cannot stat '/home/trentandraka/emacs_anywhere.el': No such file or directory
cp: cannot stat '/home/trentandraka/bin/emacstask': No such file or directory
cp: cannot stat '/home/trentandraka/bin/linux': No such file or directory
Emacs Anywhere has been installed

It wasn't installed correctly, however, since trying to set the shortcut with the provided terminal command doesn't work. What's the fix?

I get that the GNU/Linux release is still in alpha, just wanted to point this out and provide feedback that is hopefully of use.

update the content with a keystroke without deleting the frame

Hello!

I would like to recommend a keystroke to update the content of the original window while still editing.

This is useful where the interaction with the text is much longer -- i.e. when one doesn't just jump into the editor and out.

But even here when writing this issue text. I'd like to:

  • open it in emacs, change to Markdown mode
  • type some text
  • call some function to update the issue text
  • check the Markdown preview, then back to writing mode
  • continue editing in emacs
  • ...
  • close the frame, done

In particular I was thinking of this when using Shadertoy. There, the text input is in a Codemirror enabled area.

Not working with Aquamacs ?

I tried emacs-anywhere on my Mac. It's working with

GNU Emacs 25.3.1 (x86_64-apple-darwin13.4.0, NS appkit-1265.21 Version 10.9.5 (Build 13F1911))
of 2017-09-12

but not with

Aquamacs 3.3 GNU Emacs 25.1.1 (x86_64-apple-darwin14.1.0, NS appkit-1344.72 Version 10.10.2 (Build 14C109)) of 2016-09-20

On both, an emacs-anywhere buffer open, but it's still spinning on the top with Aquamacs when I close the frame. Anything I'm doing wrong ?

More robust pasting

Hello,

I notice that ATM, we use Ctrl+v for pasting. Quite a few apps (e.g. emacs, terminal) use that for something else. It seems that a much safer method (used by CopyQ) is to use Shift+Insert.

xdotool key --clearmodifiers ctrl+v

Perhaps this should be used instead?

README should be more clear about where to put configuration

README should be more clear about where to put configuration

Hello and greetings, fellow human.

The README does not make it clear that the variables, hooks et cetera should be set on the Emacs server (i.e. placed in init.el).

I heartily thank you for reading.


Written using Emacs with Emacs Anywhere. Submitted with Firefox on OSX.

Does this work on mojave?

❯ curl -fsSL https://raw.github.com/zachcurry/emacs-anywhere/master/install | bash
dependency check passed: emacsclient
dependency check passed: git
Installing Emacs Anywhere...
Cloning into '/Users/john/.emacs_anywhere'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 256 (delta 0), reused 0 (delta 0), pack-reused 252
Receiving objects: 100% (256/256), 1.36 MiB | 18.56 MiB/s, done.
Resolving deltas: 100% (119/119), done.
Copying /Users/john/.emacs_anywhere/Emacs Anywhere.workflow to /Users/john/Library/Services...
cp: /Users/john/Library/Services/Emacs Anywhere.workflow: Permission denied
cp: /Users/john/.emacs_anywhere/Emacs Anywhere.workflow: unable to copy extended attributes to /Users/john/Library/Services/Emacs Anywhere.workflow: Permission denied
cp: /Users/john/Library/Services/Emacs Anywhere.workflow/Contents: No such file or directory
cp: /Users/john/.emacs_anywhere/Emacs Anywhere.workflow/Contents: unable to copy extended attributes to /Users/john/Library/Services/Emacs Anywhere.workflow/Contents: No such file or directory
cp: /Users/john/Library/Services/Emacs Anywhere.workflow/Contents/QuickLook: No such file or directory
cp: /Users/john/.emacs_anywhere/Emacs Anywhere.workflow/Contents/QuickLook: unable to copy extended attributes to /Users/john/Library/Services/Emacs Anywhere.workflow/Contents/QuickLook: No such file or directory
cp: /Users/john/Library/Services/Emacs Anywhere.workflow/Contents/QuickLook/Thumbnail.png: No such file or directory
cp: /Users/john/Library/Services/Emacs Anywhere.workflow/Contents/document.wflow: No such file or directory
cp: /Users/john/Library/Services/Emacs Anywhere.workflow/Contents/Info.plist: No such file or directory

Add it in Homebrew?

Hiya there,
Thanks for that tool which sounds promising and fun :-)
Have you ever thought about releasing it on Homebrew?

Emacs anywhere fails when in OSX "Firefox Developer Edition"

Attempting to paste into "Firefox Developer Edition", emacs-anywhere would close the frame and paste its contents into whatever buffer was open in the main emacs instance. Renaming to "Firefox" fixed the issue for me.

Mac OSX High Sierra 10.13.4

Macos

~/.emacs_anywhere/bin/emacstask: line 9: emacsclient: command not found

Does not work on Ubuntu (spam)

This release does not work on Ubuntu as is stated. I don't use Wayland. See previous issues that are closed for reproduction of error.

Didn't work on my Linux setup

I have an xmonad setup on top of Ubuntu. I debugged and found that the reason why it wasn't working on my machine: After the elisp command (kill-buffer "*Emacs Anywhere*") gets executed, the X clipboard doesn't have anything in the clipboard. I changed the algorithm slightly like this:

(require 'f)

(defun ea-on-delete (frame)
  (f-write (buffer-string) 'utf-8 "~/.emacs_anywhere/clipboard"))

And then it started working. Ofcourse, I also had to change the run command accordingly. Honestly, I find relying on Clipboard in Linux to be troublesome. I can send you a PR if you agree to change the logic the above way.

Question: How to launch under cursor?

Hi,

I've just started using this and like it so far. There's one thing I can't work out how to do, I'm hoping someone can help me with this.

I have windows focus set to where my cursor is, so if emacs-anywhere starts somewhere outside of my cursor position, then it doesn't get focus.

I'm thinking the best solution to this would be to position the middle of the emacs-anywhere window just under the cursor.

Thanks in advance,

tecosaur.

p.s. I don't know if this is relevant, but I'm setting the size with (set-frame-size (selected-frame) 80 12)

linux: provide arch PKGBUILD

Hi and thanks for the fine program. Just filling in this issue so that we maybe have in the future a package for arch users on the AUR repo.

thanks again

Install and uninstall scripts fail when not run from the root of the repo

$ ./emacs-anywhere/install
cp: /Users/gisborne/emacs_anywhere.el: No such file or directory
cp: /Users/gisborne/bin/emacstask: No such file or directory
cp: /Users/gisborne/bin/osx: No such file or directory
cp: /Users/gisborne/Emacs Anywhere.workflow: No such file or directory
Emacs Anywhere has been installed

Emacs anywhere freezes i3 and does not paste

Hi @zachcurry, I have read on this wonderful package on Reddit and today I finally had time to try it out!

I am using i3 as window manager and Ubuntu 16.04 and will try to explain what happens when I use Emacs Anywhere.

Basically the emacs window opens fine and I can write, but on frame close i3 gets stuck for something that it seems like 5 seconds, without being able to to keypress anything except that canonical Ctrl+Alt+F1/2/4/5 for terminals. After that time, everything goes back to normal. No paste happens.

Let me know if I can try something else on my side for debugging.

Thank you very much again!

Support for OpenBSD

I'd like to know why there is no support for OpenBSD. Is there any tool been used that ties it to Linux and GNU/Linux distributions? What would be needed to add support to OpenBSD (and, while I'm at it, the other BSD's too)?

Can't launch emacs anywhere

When I try to activate my shortcut I get an error message

The action “Run AppleScript” encountered an error: “emacsclient: could not get terminal name
emacsclient: error executing alternate editor ""”

emacs and emacsclient are both PATH variables for me.

I'm using MacOS 10.13.3

Do not hardcore installation directory

This would make it possible to just add it to path from anywhere, and it would even be possible to set up with straight.el and use-package. This kind of makes sense as it is strictly an emacs-related plugin so it should be configurable inside .emacs.d. It wouldn't be the first time that non-elisp stuff went into an Emacs package (e.g. tide and it's tsserver directory)

Copy selection to clipboard when invoked.

Would be nice if I select something in the text box before opening emacs to have it appear in the emacs buffer so I can edit it before pasting again. Here is how to do it (two trivial changes; feel free to incorporate it if you want, or I can create a pull request if you prefer, or just ignore it):

on run {input, parameters}
	tell application "System Events"
		set appName to name of first application process whose frontmost is true
		keystroke "c" using command down  -- copy before launching emacs; the yank later pastes it in emacs buffer
	end tell
	do shell script "PATH=/Applications/Emacs.app/Contents/MacOS/bin/:$PATH ; emacsclient -a \"\" -c -e \"(progn
  (defun ea-clipboard-save (frame)
    (clipboard-kill-ring-save
     (point-min)
     (point-max))
   (kill-buffer \\\"*Emacs Anywhere*\\\"))
  (defun ea-hook-clipboard-save ()
    (add-hook 'delete-frame-functions 'ea-clipboard-save))
  (defun ea-unhook-clipboard-save ()
    (remove-hook 'delete-frame-functions 'ea-clipboard-save))
  (defun emacs-anywhere ()
    (interactive)
    (if (y-or-n-p \\\"Emacs Anywhere: Delete *Emacs Anywhere* buffer and copy current buffer to clipboard on frame delete? \\\")
        (ea-hook-clipboard-save)
      (ea-unhook-clipboard-save)))
  (ea-hook-clipboard-save)
  (switch-to-buffer \\\"*Emacs Anywhere*\\\")
  (yank)
 (select-frame-set-input-focus (selected-frame)))\""
	tell application appName to activate
	tell application "System Events" to keystroke "v" using command down -- comment this line ine to disable auto-paste
	return
end run

(edited to format code)

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.