Personal_Plant_375 · 2022-09-06 13:41
[https://github.com/ginqi7/global-interactive-emacs](https://github.com/ginqi7/global-interactive-emacs)
This tool is inspired by article : [Global interactive Emacs functions](https://isamert.net/2022/03/16/global-interactive-emacs-functions.html). It provides an idea to run Emacs functions outside of Emacs.
So I try to use this idea to wrtie a tool like [lauchbar](https://www.obdev.at/products/launchbar/index.html) or [Alfred](https://www.alfredapp.com/). It can help user to quickly lauch app or run work flow.
I’m using it to replace the lauchbar.
# Pros and cons
This tool has some pros and cons, and I think if you have the following needs, you can try to use it :
* you don’t want to pay for other tools like [lauchbar](https://www.obdev.at/products/launchbar/index.html) or [Alfred](https://www.alfredapp.com/).
* you wish some function in Emacs could run out of Emacs.
* You’re familiar with Emacs, there are some plugins, and custom functions that you want to reuse.
* You don’t want to learn a new language or workflow of a new software
* …
## Pros
* **free**: Whether Lauchbar or Alfred, you need to pay for it to use it comfortably and efficiently. Just need Emacsand some open source software that you can use for free.
* **consistency**: You can use the same features inside or outside of Emacs and have a similar experience.
* **Simple Configuration**: If you are familiar with Emacs, you can easily configure it with emacs-lisp without having to relearn the language and process of other tools.
* **Scalability**: You can write your own interactive functions and plug them into the tool, or use the Emacs plugins developed by others to extract the interaction functions and plug them into the tool.
## Cons
* **Not powerful for now**: Obviously, the tool is not as powerful as lauchbar or Alfred. At the moment, it is only useful for my own needs. I will continue to improve according to my needs, and anyone is welcome to help improve it.
* **Can’t perfectly support all Emacs interactive functions**: There are currently some Emacs interaction functions that cannot be run outside of Emacs, such as execute-extended-command. I don’t have the train of thought to support it yet.
# Example
## global-interactive-select-from-clipboard
​
https://i.redd.it/nbisbqzjr8m91.gif
## global-interactive-run-app
You could quickly launch apps in you MacOS.
​
https://i.redd.it/5r8h90amr8m91.gif
## global-interactive-open-url
You could quickly jump pre define urls.
​
https://i.redd.it/by4kx7yor8m91.gif
## global-interactive-kubectl
You could conbine other Emacs plugin, have a similar experience in or out of Emacs.
The kubectl plugin is [here](https://github.com/ginqi7/kubectl-emacs).
​
https://i.redd.it/0516v9mtr8m91.gif
## global-interactive-leetcode
The leetcode plugin is [here](https://github.com/ginqi7/leetcode-emacs).
​
https://i.redd.it/3egkrfnvr8m91.gif
## global-interactive-youdao-dictionary
The youdao-dictionary plugin is [here](https://github.com/xuchunyang/youdao-dictionary.el).
You could using it to transalte word, and copy the translated value.
​
https://i.redd.it/kgxgj2wzr8m91.gif
If you don’t select any item, it will copy the whole translation.
If you selete one line, it will copy the line.
## global-interactive-web-search
Define some search engine, and input some text to query.
​
https://i.redd.it/9ormt8b2s8m91.gif
## global-interactive-send-request
​
https://i.redd.it/9pozglv4s8m91.gif
* the request will use chrome cookies. So once you’re logged into a website in Chrome, you can query the interface with permission verification directly through global-interactive-send-request.
* it support getand postmethod.
* it could select text from king-ringas url or body.
* it could parse json response, and interactively preview the response body.
* every time interactively select a json part, it will copy the json.
## global-interactive-find-file
​
https://i.redd.it/dsmomi87s8m91.gif
* the base path default is ‘\~/’
* you can interactively select a file.
* when you select a file, you can run a action on this file.
* you can copy file name, path or content.
## global-interactive-chrome-bookmarks
​
https://i.redd.it/aghta1uas8m91.gif
## global-interactive-chrome-history
​
https://i.redd.it/5p5zzjtbs8m91.gif
nv-elisp · 2022-09-06 18:03
Why not just open a new frame dedicated to the "global" task?
For example, https://gist.github.com/progfolio/af627354f87542879de3ddc30a31adc1
ieure · 2022-09-06 23:57
[You don't need global interactive functions if you never leave Emacs](https://preview.redd.it/h12tthcbmx741.jpg?width=960&crop=smart&auto=webp&s=1a9a6364da6f034fa8910258af8b5e38f0a8f11e)
arthurno1 · 2022-09-07 18:49
Just to let you know, Rofi is an optional application on gnu/Linux, you don't mention it anywhere in your Readme as a requirement. I see call to Rofi hardcoded in your code:
(defun global-interactive-choose (prompt items &rest ignored)
"Like `completing-read' but instead use dmenu.
Useful for system-wide scripts.
PROMPT is interactive prompt.
ITEMS is select candiates.
IGNORED is &rest."
(with-temp-buffer
(thread-first
(cond
((functionp items)
(message (format "%s" (funcall items "" nil t))))
((listp (car items))
(mapcar #'car items))
(t items))
(string-join "\n")
string-trim
insert)
(shell-command-on-region
(point-min)
(point-max)
(pcase system-type
('gnu/linux
(format "rofi -dmenu -fuzzy -i -p '%s'" prompt))
('darwin "choose -m"))
nil t "*global-interactive-choose error*" nil)
(string-trim (buffer-string))))
It is probably OK to use it as a search backend, but you should probably provide a built-in solution without Rofi and have some sort of test or user configuration so users can switch between Rofi or something else. It should not be very hard/impossible to provide an alternative. There are some other similar projects where someone created launcher to mimic Rofi but in plain Emacs + Ivy or what is Helm, I don't remember. After all, a point of a launcher is to replace a launcher, not to have it a dependency. Rofi replaces dmenu as a better alternative, it does not require dmenu.
Also, you have hard-coded ' '/Aplications' path. There is no such path by default on either gnu/Linux or MS Windows, as far as I know. I am looking at this:
(defun global-interactive-app-command--find-all-app ()
"Find all apps in system."
(let* ((output
(split-string
(shell-command-to-string "ls -1 /Applications")
"\n" t " +")))
(setq global-interactive-app-command
(mapcar
(lambda (path) (string-remove-suffix ".app" path))
output))))
Otherwise, it looks nice. Very simple and clean
Personal_Plant_375 · 2022-09-08 04:21
Thank you for your advice.
Use "rofi" in Linux and use "choose" in Mac as default, because I cannot use native Emacs to implement it.
There are other choices to use "posframe", which looks good, but when close Emacs frame, it cannot concentrate other origin windows.
Your idea is right. I should extract the backend from the core code and add a configuration variable to choose which backend to use.
Use "/Application" to list applications in MacOS. Because I only have MacOS and I can't test other systems.
Maybe I should extract it and let the user configure.
arthurno1 · 2022-09-08 11:31
> Use "rofi" in Linux and use "choose" in Mac as default, because I cannot use native Emacs to implement it.
I don't think you need to implement rofi. You just need basic directory lister, which Emacs already has, check directory-files, which is implemented in C and probably fast enough for your needs. It is quite capable. Emacs also has file-executable-p so you can check if a file is executable or not. Basically walk the exec-path and collect all executables in a list which you can feed into the compleating-read function (or whatever you use). I think. Certainly won't be as fast as a C application such as rofi, but it should work. You could also use a shell command to find executables with only find, or with ls | grep or something similar. Those should be more widespread than Rofi in gnu/linux world.
> I should extract the backend from the core code and add a configuration variable to choose which backend to use.
> Maybe I should extract it and let the user configure.
Perhaps. You can definitely use Emacs built-in variable exec-path. But that can vary from their PATH variable seen from the bash if Emacs is started as daemon or because of some other configuration. Depending on how much flexibility you would like to have, you might wish to make it easy for yourself and ride on the exec-path and let people customize that one (which many already do I think), or you might add some defcustom or defvar to add some additional places.
> Use "/Application" to list applications in MacOS. Because I only have MacOS and I can't test other systems.
[VirtualBox](https://www.virtualbox.org/) or something similar should do for some basic OS installation in this case? Or you could make use of free 1 year subscription to AWS and test in EC2. But it is much simpler with virtualbox :).