├── .gitignore
├── CONTRIBUTING.md
├── EmacsAnywhere.workflow
└── Contents
│ ├── Info.plist
│ └── document.wflow
├── LICENSE
├── README.md
├── assets
├── demo.gif
└── shortcut.png
├── bin
└── run
├── install
├── script
├── current_app.scpt
└── open_shortcuts.scpt
├── uninstall
└── update
/.gitignore:
--------------------------------------------------------------------------------
1 | # generated by vim-anywhere on OSX only
2 | .path
3 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Thanks for your interest in contributing to emacs-anywhere.
2 |
3 | Few things to keep in mind:
4 |
5 | * BNBR - Be nice be respectful
6 | * Raise well tested pull requests
--------------------------------------------------------------------------------
/EmacsAnywhere.workflow/Contents/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 | NSServices
11 |
12 |
13 | NSMenuItem
14 |
15 | default
16 | EmacsAnywhere
17 |
18 | NSMessage
19 | runWorkflowAsService
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/EmacsAnywhere.workflow/Contents/document.wflow:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 | AMApplicationBuild
11 | 381
12 | AMApplicationVersion
13 | 2.4
14 | AMDocumentVersion
15 | 2
16 | actions
17 |
18 |
19 | action
20 |
21 | AMAccepts
22 |
23 | Container
24 | List
25 | Optional
26 |
27 | Types
28 |
29 | com.apple.cocoa.string
30 |
31 |
32 | AMActionVersion
33 | 2.0.3
34 | AMApplication
35 |
36 | Automator
37 |
38 | AMParameterProperties
39 |
40 | COMMAND_STRING
41 |
42 | CheckedForUserDefaultShell
43 |
44 | inputMethod
45 |
46 | shell
47 |
48 | source
49 |
50 |
51 | AMProvides
52 |
53 | Container
54 | List
55 | Types
56 |
57 | com.apple.cocoa.string
58 |
59 |
60 | ActionBundlePath
61 | /System/Library/Automator/Run Shell Script.action
62 | ActionName
63 | Run Shell Script
64 | ActionParameters
65 |
66 | COMMAND_STRING
67 | $HOME/.emacs-anywhere/bin/run
68 | CheckedForUserDefaultShell
69 |
70 | inputMethod
71 | 0
72 | shell
73 | /bin/bash
74 | source
75 |
76 |
77 | BundleIdentifier
78 | com.apple.RunShellScript
79 | CFBundleVersion
80 | 2.0.3
81 | CanShowSelectedItemsWhenRun
82 |
83 | CanShowWhenRun
84 |
85 | Category
86 |
87 | AMCategoryUtilities
88 |
89 | Class Name
90 | RunShellScriptAction
91 | InputUUID
92 | 6FFA24CD-4E05-4C6A-A6FB-E32CF835C918
93 | Keywords
94 |
95 | Shell
96 | Script
97 | Command
98 | Run
99 | Unix
100 |
101 | OutputUUID
102 | 38133079-F4E2-4D5F-9B21-6BBAFABD7CE9
103 | UUID
104 | B374B8A3-8D8E-4327-9A92-826742A01517
105 | UnlocalizedApplications
106 |
107 | Automator
108 |
109 | arguments
110 |
111 | 0
112 |
113 | default value
114 | 0
115 | name
116 | inputMethod
117 | required
118 | 0
119 | type
120 | 0
121 | uuid
122 | 0
123 |
124 | 1
125 |
126 | default value
127 |
128 | name
129 | source
130 | required
131 | 0
132 | type
133 | 0
134 | uuid
135 | 1
136 |
137 | 2
138 |
139 | default value
140 |
141 | name
142 | CheckedForUserDefaultShell
143 | required
144 | 0
145 | type
146 | 0
147 | uuid
148 | 2
149 |
150 | 3
151 |
152 | default value
153 |
154 | name
155 | COMMAND_STRING
156 | required
157 | 0
158 | type
159 | 0
160 | uuid
161 | 3
162 |
163 | 4
164 |
165 | default value
166 | /bin/sh
167 | name
168 | shell
169 | required
170 | 0
171 | type
172 | 0
173 | uuid
174 | 4
175 |
176 |
177 | conversionLabel
178 | 0
179 | isViewVisible
180 |
181 | location
182 | 289.500000:499.000000
183 | nibPath
184 | /System/Library/Automator/Run Shell Script.action/Contents/Resources/English.lproj/main.nib
185 |
186 | isViewVisible
187 |
188 |
189 |
190 | connectors
191 |
192 | workflowMetaData
193 |
194 | serviceInputTypeIdentifier
195 | com.apple.Automator.nothing
196 | serviceOutputTypeIdentifier
197 | com.apple.Automator.nothing
198 | serviceProcessesInput
199 | 0
200 | workflowTypeIdentifier
201 | com.apple.Automator.servicesMenu
202 |
203 |
204 |
205 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Prathik Raj
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # emacs-anywhere
2 |
3 | ## Why?
4 |
5 | Many times you'd like to edit or create content on Emacs and then put it somewhere else. This process is made seamless. Hit the keyboard shortcut to load emacs and when you save and quit that content will be copied on to the clipboard.
6 |
7 | emacs-anywhere is currently built for Mac OSX.
8 |
9 | 
10 |
11 | Once [invoked](#keybinding), emacs-anywhere will open a buffer. Close it and its
12 | contents are copied to your __clipboard__ and your previous application is
13 | refocused.
14 |
15 | ## Installation
16 |
17 | #### Requirements
18 |
19 | __OSX:__
20 |
21 | - Emacs with GUI (`brew install emacs --with-cocoa`)
22 |
23 | #### Install
24 |
25 | ```bash
26 | curl -fsSL https://raw.github.com/prathik/emacs-anywhere/master/install | bash
27 | ```
28 |
29 | __OSX caveat:__ key binding is unbound by default. See [keybinding](#keybinding)
30 | for details.
31 |
32 | #### Update
33 |
34 | ```bash
35 | ~/.emacs-anywhere/update
36 | ```
37 |
38 | #### Uninstall
39 |
40 | ```bash
41 | ~/.emacs-anywhere/uninstall
42 | ```
43 |
44 | ## Keybinding
45 |
46 | __OSX:__ ( default = unbound, suggested = `ctrl+cmd+v` )
47 |
48 | The keyboard shortcut for invoking emacs-anywhere is unbound by default on OSX.
49 | The installation script will automatically open
50 | `System Preferences > Keyboard > Shortcuts`. Fill in the following:
51 |
52 | 
53 |
54 | ## History
55 |
56 | emacs-anywhere creates a temporary file in `/tmp/emacs-anywhere` when
57 | invoked. These files stick around until you restart your system, giving you
58 | a temporary history.
59 |
60 | View your history:
61 |
62 | ```bash
63 | $ ls /tmp/emacs-anywhere
64 | ```
65 |
66 | Reopen your most recent file:
67 |
68 | ```bash
69 | $ emacs $( ls /tmp/emacs-anywhere | sort -r | head -n 1 )
70 | ```
71 |
72 | ## Contributing
73 |
74 | Pull requests, suggestions and issues of any kind are welcome with open arms.
75 |
76 | ## Credits
77 | emacs-anywhere is inspired from [cknadler/vim-anywhere](https://github.com/cknadler/vim-anywhere) and is a fork of it to work on emacs. Shout out to [@cknadler](https://github.com/cknadler/) for his awesome work on vim-anywhere.
78 |
79 | ## License
80 |
81 | MIT.
82 |
--------------------------------------------------------------------------------
/assets/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prathik/emacs-anywhere/59fec96b8093b2a111592505b75de2fbd65f4bec/assets/demo.gif
--------------------------------------------------------------------------------
/assets/shortcut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prathik/emacs-anywhere/59fec96b8093b2a111592505b75de2fbd65f4bec/assets/shortcut.png
--------------------------------------------------------------------------------
/bin/run:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # emacs-anywhere - use Emacs whenever, wherever
4 | # Author: Prathik Raj
5 | # Homepage: https://www.github.com/prathik/emacs-anywhere
6 | #
7 | # Open a temporary file with Emacs. Once Emacs is closed, copy the contents of that
8 | # file to the system clipboard.
9 |
10 | ###
11 | # defs
12 | ###
13 |
14 | err() { echo -e "$@" 1>&2; }
15 |
16 | require_file_exists() {
17 | if [ ! -e $1 ]; then
18 | err "$1 does not exist. ${@:2}"
19 | exit 1
20 | fi
21 | }
22 |
23 | ###
24 | # opts
25 | ###
26 |
27 | while getopts ":v" opt; do
28 | case "$opt" in
29 | v) set -x ;;
30 | \?) echo "Invalid option: -$OPTARG" >&2 ;;
31 | esac
32 | done
33 |
34 | ###
35 | # run
36 | ###
37 |
38 | AW_PATH=$HOME/.emacs-anywhere
39 | TMPFILE_DIR=/tmp/emacs-anywhere
40 | TMPFILE=$TMPFILE_DIR/doc-$(date +"%y%m%d%H%M%S")
41 |
42 | mkdir -p $TMPFILE_DIR
43 | touch $TMPFILE
44 |
45 | # OSX
46 | if [[ $OSTYPE == "darwin"* ]]; then
47 | # if there is no path file, it must have been deleted or the installer failed
48 | require_file_exists $AW_PATH/.path \
49 | "Please reinstall emacs-anywhere."
50 |
51 | app=$(osascript $AW_PATH/script/current_app.scpt)
52 | # Uncomment below line to auto-paste
53 | # whatever is copied on to the newly
54 | # created file
55 | # pbpaste >> $TMPFILE
56 | /usr/local/bin/emacsclient -c $TMPFILE || open -W -a Emacs $TMPFILE
57 | # todo, fix invalid file
58 |
59 | # NOTE
60 | # Here we set LANG explicitly to be UTF-8 compatible when copying text. The only way that was explicitly
61 | # setting this to en_US.UTF-8. This may eventually cause issues with other languages. If so, just remove
62 | # the LANG setting.
63 | # LANG=en_US.UTF-8
64 | LANG=en_US.UTF-8
65 | pbcopy < $TMPFILE
66 | osascript -e "activate application \"$app\""
67 | fi
68 |
--------------------------------------------------------------------------------
/install:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # emacs-anywhere - use Emacs whenever, wherever
4 | # Author: Prathik Raj
5 | # Homepage: https://www.github.com/prathik/emacs-anywhere
6 | #
7 | # Installs emacs-anywhere. Intended for use via curl:
8 | #
9 | # $ curl -fsSL https://raw.github.com/prathik/emacs-anywhere/master/install | bash
10 |
11 | set -e
12 |
13 | ###
14 | # opts
15 | ###
16 |
17 | while getopts ":v" opt; do
18 | case "$opt" in
19 | v) set -x ;;
20 | \?) echo "Invalid option: -$OPTARG" >&2 ;;
21 | esac
22 | done
23 |
24 | ###
25 | # defs
26 | ###
27 |
28 | err() { echo -e "$@" 1>&2; }
29 |
30 | check_installed() { hash $1 &> /dev/null; }
31 |
32 | require_installed() {
33 | if ! check_installed $1; then
34 | err "emacs-anywhere requires $1 to function"
35 | if [[ "$2" != "" ]]; then echo $2; fi
36 | exit 1
37 | fi
38 | }
39 |
40 | require_one_installed() {
41 | for file in $*; do
42 | check_installed $file && return
43 | done
44 | err "emacs-anywhere requires one of the following to be installed:\n$*"
45 | exit 1
46 | }
47 |
48 | AW_PATH=$HOME/.emacs-anywhere
49 | AW_URL='https://github.com/prathik/emacs-anywhere'
50 |
51 | ###
52 | # pre-installation checks
53 | ###
54 |
55 | # Check if emacs-anywhere is already installed. If so, remove the previous
56 | # installation.
57 | if [ -a $AW_PATH ]; then
58 | echo 'Cleaning up previous installation...'
59 | rm -rf $AW_PATH
60 | # TODO: It would be nice to have an option for user input here
61 | # Reinstall emacs-anywhere (y/n)? ... or something like that
62 | fi
63 |
64 | require_installed git
65 |
66 | # if we are in a git repo, unset env vars
67 | if git rev-parse --git-dir &> /dev/null; then
68 | unset $(git rev-parse --local-env-vars) &> /dev/null
69 | fi
70 |
71 | if [[ $OSTYPE == "darwin"* ]]; then
72 | require_installed emacs 'Run `brew install emacs --with-cocoa`.'
73 |
74 | # Check for Emacs with GUI support
75 | if ! open -a Emacs --args --eval "(kill-emacs)"; then
76 | echo 'Emacs has not been installed with GUI support'
77 | echo 'Please run brew install emacs --with-cocoa'
78 | exit 1
79 | fi
80 | # Unsupported OS
81 | else
82 | echo "OS '$OSTYPE' is not supported!"
83 | exit 1
84 | fi
85 |
86 | ###
87 | # installation
88 | ###
89 |
90 | echo "Installing emacs-anywhere..."
91 |
92 | git clone $AW_URL $AW_PATH
93 |
94 | # OSX install
95 | if [[ $OSTYPE == "darwin"* ]]; then
96 | # store the absolute path to the mvim executable
97 | which emacs > $AW_PATH/.path
98 |
99 | # install the workflow as a service
100 | mkdir -p $HOME/Library/Services
101 | cp -R $AW_PATH/EmacsAnywhere.workflow $HOME/Library/Services
102 |
103 | # TODO: add shortcut
104 | # It would be great if there was a way to set the keyboard shortcut for
105 | # emacs-anywhere programatically (without GUI scripting). If there ends up being a
106 | # way to do this, it would go here.
107 |
108 | # As a partial workaround, run a script that opens the shortcut options
109 | echo "Opening System Preferences..."
110 | osascript $AW_PATH/script/open_shortcuts.scpt &> /dev/null
111 | fi
112 |
113 | echo "emacs-anywhere has been successfully installed!"
114 |
--------------------------------------------------------------------------------
/script/current_app.scpt:
--------------------------------------------------------------------------------
1 | -- emacs-anywhere - use Emacs whenever, wherever
2 | -- Author: Prathik Raj
3 | -- Homepage: https://www.github.com/prathik/emacs-anywhere
4 | --
5 | -- Get the current application's name
6 |
7 | tell application "System Events"
8 | copy (name of application processes whose frontmost is true) to stdout
9 | end tell
10 |
--------------------------------------------------------------------------------
/script/open_shortcuts.scpt:
--------------------------------------------------------------------------------
1 | -- emacs-anywhere - use Emacs whenever, wherever
2 | -- Author: Prathik Raj
3 | -- Homepage: https://www.github.com/prathik/emacs-anywhere
4 | --
5 | -- Open the keyboard shortcuts tab of keyboard system preferences
6 |
7 | tell application "System Preferences"
8 | activate
9 | reveal anchor "shortcutsTab" of pane id "com.apple.preference.keyboard"
10 | end tell
11 |
--------------------------------------------------------------------------------
/uninstall:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # emacs-anywhere - use Emacs whenever, wherever
4 | # Author: Prathik Raj
5 | # Homepage: https://www.github.com/prathik/emacs-anywhere
6 | #
7 | # Uninstalls emacs-anywhere
8 |
9 | set -e
10 |
11 | ###
12 | # opts
13 | ###
14 |
15 | while getopts ":v" opt; do
16 | case "$opt" in
17 | v) set -x ;;
18 | \?) echo "Invalid option: -$OPTARG" >&2 ;;
19 | esac
20 | done
21 |
22 | ###
23 | # defs
24 | ###
25 |
26 | check_installed() { hash $1 &> /dev/null; }
27 |
28 | AW_PATH=$HOME/.emacs-anywhere
29 | DOC_PATH=/tmp/emacs-anywhere
30 |
31 | ###
32 | # uninstall
33 | ###
34 |
35 | rm -rf $AW_PATH $DOC_PATH
36 |
37 | # OSX uninstall
38 | if [[ $OSTYPE == "darwin"* ]]; then
39 | rm -rf $HOME/Library/Services/EmacsAnywhere.workflow
40 | fi
41 |
42 | echo "emacs-anywhere has been successfully uninstalled!"
43 |
--------------------------------------------------------------------------------
/update:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # emacs-anywhere - use Emacs whenever, wherever
4 | # Author: Prathik Raj
5 | # Homepage: https://www.github.com/prathik/emacs-anywhere
6 | #
7 | # Updates emacs-anywhere
8 |
9 | set -e
10 |
11 | ###
12 | # opts
13 | ###
14 |
15 | while getopts ":v" opt; do
16 | case "$opt" in
17 | v) set -x ;;
18 | \?) echo "Invalid option: -$OPTARG" >&2 ;;
19 | esac
20 | done
21 |
22 | ###
23 | # defs
24 | ###
25 |
26 | err() { echo -e "$@" 1>&2; }
27 |
28 | AW_PATH=$HOME/.emacs-anywhere
29 |
30 | ###
31 | # update
32 | ###
33 |
34 | if [ ! -d $AW_PATH ]; then
35 | err "emacs-anywhere doesn't seem to be installed."
36 | exit 1
37 | fi
38 |
39 | # if we are in a git repo, unset env vars
40 | if git rev-parse --git-dir &> /dev/null; then
41 | unset $(git rev-parse --local-env-vars) &> /dev/null
42 | fi
43 |
44 | pushd $AW_PATH
45 | git pull origin master
46 | [ $? -ne 0 ] && exit 1
47 | popd
48 |
49 | # OSX only
50 | if [[ $OSTYPE == "darwin"* ]]; then
51 | cp -R $AW_PATH/EmacsAnywhere.workflow $HOME/Library/Services
52 | fi
53 |
54 | echo "emacs-anywhere has been successfully updated!"
55 |
--------------------------------------------------------------------------------