global-interactive-emacs
global-interactive-emacs copied to clipboard
Global Interactive Emacs
#+title: Global Interactive Emacs #+author: Qiqi Jin #+language: en
This tool is inspired by article : [[https://isamert.net/2022/03/16/global-interactive-emacs-functions.html][Global interactive Emacs functions]]. It provides an idea to run Emacs functions outside of Emacs.
So I try to use this idea to wrtie a tool like [[https://www.obdev.at/products/launchbar/index.html][lauchbar]] or [[https://www.alfredapp.com/][Alfred]]. 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 [[https://www.obdev.at/products/launchbar/index.html][lauchbar]] or [[https://www.alfredapp.com/][Alfred]].
- 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 =Emacs= and 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.
- Prerequisites
- choose
[[https://github.com/chipsenkbeil/choose][choose github]]
=Global Interactive Emacs= use it as interface to interactively communicate with Emacs.
Maybe using rofi is okay on Linux, but I only have Mac OS and can't test it.
- Installing
-
clone the project in your own emacs configuration files directory, like: #+BEGIN_SRC sh git clone [email protected]:ginqi7/global-interactive-emacs.git ~/.emacs.d/lisp/global-interactive-emacs #+END_SRC
-
add the path to 'load-path' #+BEGIN_SRC emacs-lisp (add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/d/lisp/global-interactive-emacs")) #+END_SRC
- Configuration I split different functions into different files, you can choose by your needs.
#+BEGIN_SRC emacs-lisp (require 'global-interactive-emacs) (require 'global-interactive-run-app) (require 'global-interactive-open-url) (require 'global-interactive-leetcode) (require 'global-interactive-kubectl) (require 'global-interactive-youdao-dictionary) (require 'global-interactive-web-search) (require 'global-interactive-send-request) (require 'global-interactive-find-file) (require 'global-interactive-chrome-bookmarks) (require 'global-interactive-chrome-history) #+end_src
** global-interactive-run-app You could run 'global-interactive-run-app-init' in your init file, it will find your apps in your '/Applications' directory. If you don't run it manual, it will be called in your first choose launch some apps. #+begin_src emacs-lisp (global-interactive-run-app-init) #+end_src
** global-interactive-open-url You could define some urls to quickly jump to selected url. The configuration is using yaml file or emacs plist.
If you use emacs plist to define urls: #+begin_src emacs-lisp (setq global-interactive-url-plist (:movie [(:Doctor\ Strange\ in\ the\ Multiverse\ of\ Madness "https://www.imdb.com/title/tt9419884/?ref_=hm_fanfav_tt_t_1_pd_fp1") (:The\ Batman "https://www.imdb.com/title/tt1877830/?ref_=hm_tpks_tt_t_2_pd_tp1_pbr_ic")] :music [(:jay\ chou "https://www.wikiwand.com/en/List_of_songs_recorded_by_Jay_Chou")]) #+end_src
If you use yaml to define urls:
-
you need add package: [[https://github.com/zkry/yaml.el][yaml]]
-
you need save yaml config to a file. It's values like: #+begin_src yaml movie:
- Doctor Strange in the Multiverse of Madness: https://www.imdb.com/title/tt9419884/?ref_=hm_fanfav_tt_t_1_pd_fp1
- The Batman: https://www.imdb.com/title/tt1877830/?ref_=hm_tpks_tt_t_2_pd_tp1_pbr_ic music:
- jay chou: https://www.wikiwand.com/en/List_of_songs_recorded_by_Jay_Chou #+end_src
-
you need config parameter 'global-interactive-url-yaml-path'
#+begin_src emacs-lisp (setq global-interactive-url-yaml-path "some path to yaml file") #+end_src
** global-interactive-web-search Define some search engine, and input some text to query. You could define some urls to quickly jump to selected url. The configuration is using yaml file or emacs plist.
If you use emacs plist to define urls: #+begin_src emacs-lisp (setq global-interactive-web-search-plist (:Google "https://www.google.com/search?q=${param}" :Zhihu "https://www.zhihu.com/search?type=content&q=${param}") #+end_src
using ${param} as placeholder, it will replace you input text.
If you use yaml to define urls:
- you need add package: [[https://github.com/zkry/yaml.el][yaml]]
- you need save yaml config to a file. It's values like: #+begin_src yaml Google: https://www.google.com/search?q=${param} Zhihu: https://www.zhihu.com/search?type=content&q=${param} #+end_src
- you need config parameter 'global-interactive-web-search-yaml-path'
#+begin_src emacs-lisp (setq global-interactive-web-search-yaml-path "some path to yaml file") #+end_src
** global-interactive-send-request send_request need a python package [[https://github.com/n8henrie/pycookiecheat][pycookiecheat]]. It could get chrome cookies. so I write a python script =send_request.py=, it can get chrome cookie and send request to a website.
#+begin_src emacs-lisp (setq global-interactive-python-shell-path "some_path/send_request.py") #+end_src
- Usage
After you install and configurate this tool. You need start emacs server, and run:
There are three method to run 'global-interactive-emacs':
- Run 'global-interactive-emacs' in current Emacs frame. Just run '(global-interactive-emacs)'
- Run 'global-interactive-emacs' out of Emacs. You could run shell like : #+begin_src shell emacsclient --eval "(global-interactive-emacs t)" #+end_src
- Run 'global-interactive-emacs' in a new Emacs frame like out of Emacs. you coud run shell like: #+begin_src emacs-lisp emacsclient --eval "(global-interactive-frame)" #+end_src
If successfully run, you could use some tool to bind the command in a hotkey.
I use [[https://github.com/kasper/phoenix][phoenix]] to bind the command to "cmd + space".
- Features
- global-interactive-select-from-clipboard: select text from =kill-ring= and clipboard.
- global-interactive-run-app: launch installed MaOS app.
- global-interactive-open-url: using browser to open pre-define urls.
- global-interactive-leetcode: interactively query and show leetcode problem.
- global-interactive-kubectl: interactively query and open k8s resource config.
- global-interactive-youdao-dictionary: transalte word by youdao dictionary.
- global-interactive-web-search: using browser to query info by pre-define search engine.
- global-interactive-send-request: send http request with chrome cookie, and parse it's json response.
- global-interactive-find-file: find a file in system and do some action on this file.
- global-interactive-chrome-bookmarks: query chrome bookmarks.
- global-interactive-chrome-history: query chrome history.
- Example ** global-interactive-select-from-clipboard
#+HTML:

#+HTML:

** global-interactive-open-url You could quickly jump pre define urls. #+HTML:

** global-interactive-kubectl You could conbine other Emacs plugin, have a similar experience in or out of Emacs.
The kubectl plugin is [[https://github.com/ginqi7/kubectl-emacs][here]].
#+HTML:

** global-interactive-leetcode
The leetcode plugin is [[https://github.com/ginqi7/leetcode-emacs][here]].
#+HTML:

** global-interactive-youdao-dictionary
The youdao-dictionary plugin is [[https://github.com/xuchunyang/youdao-dictionary.el][here]].
You could using it to transalte word, and copy the translated value.
#+HTML:

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. #+HTML:

** global-interactive-send-request #+HTML:

- 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 =get= and =post= method.
- it could select text from =king-ring= as 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 #+HTML:

- 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
#+HTML:
** global-interactive-chrome-history #+HTML:
