Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

415 lines
17 KiB

  1. This is with-editor.info, produced by makeinfo version 6.7 from
  2. with-editor.texi.
  3. Copyright (C) 2015-2021 Jonas Bernoulli <jonas@bernoul.li>
  4. You can redistribute this document and/or modify it under the terms
  5. of the GNU General Public License as published by the Free Software
  6. Foundation, either version 3 of the License, or (at your option)
  7. any later version.
  8. This document is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. INFO-DIR-SECTION Emacs
  13. START-INFO-DIR-ENTRY
  14. * With-Editor: (with-editor). Using the Emacsclient as $EDITOR.
  15. END-INFO-DIR-ENTRY
  16. 
  17. File: with-editor.info, Node: Top, Next: Using the With-Editor package, Up: (dir)
  18. With-Editor User Manual
  19. ***********************
  20. The library ‘with-editor’ makes it easy to use the Emacsclient as the
  21. ‘$EDITOR’ of child processes, making sure they know how to call home.
  22. For remote processes a substitute is provided, which communicates with
  23. Emacs on standard output instead of using a socket as the Emacsclient
  24. does.
  25. This library was written because Magit has to be able to do the above
  26. to allow the user to edit commit messages gracefully and to edit rebase
  27. sequences, which wouldn’t be possible at all otherwise.
  28. Because other packages can benefit from such functionality, this
  29. library is made available as a separate package. It also defines some
  30. additional functionality which makes it useful even for end-users, who
  31. don’t use Magit or another package which uses it internally.
  32. This manual is for With-Editor version 3.0.4.
  33. Copyright (C) 2015-2021 Jonas Bernoulli <jonas@bernoul.li>
  34. You can redistribute this document and/or modify it under the terms
  35. of the GNU General Public License as published by the Free Software
  36. Foundation, either version 3 of the License, or (at your option)
  37. any later version.
  38. This document is distributed in the hope that it will be useful,
  39. but WITHOUT ANY WARRANTY; without even the implied warranty of
  40. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  41. General Public License for more details.
  42. * Menu:
  43. * Using the With-Editor package::
  44. * Using With-Editor as a library::
  45. * Debugging::
  46. * Command Index::
  47. * Function Index::
  48. * Variable Index::
  49. — The Detailed Node Listing —
  50. Using the With-Editor package
  51. * Configuring With-Editor::
  52. * Using With-Editor commands::
  53. 
  54. File: with-editor.info, Node: Using the With-Editor package, Next: Using With-Editor as a library, Prev: Top, Up: Top
  55. 1 Using the With-Editor package
  56. *******************************
  57. The ‘With-Editor’ package is used internally by Magit when editing
  58. commit messages and rebase sequences. It also provides some commands
  59. and features which are useful by themselves, even if you don’t use
  60. Magit.
  61. For information about using this library in you own package, see
  62. *note Using With-Editor as a library::.
  63. * Menu:
  64. * Configuring With-Editor::
  65. * Using With-Editor commands::
  66. 
  67. File: with-editor.info, Node: Configuring With-Editor, Next: Using With-Editor commands, Up: Using the With-Editor package
  68. 1.1 Configuring With-Editor
  69. ===========================
  70. With-Editor tries very hard to locate a suitable ‘emacsclient’
  71. executable, so ideally you should never have to customize the option
  72. ‘with-editor-emacsclient-executable’. When it fails to do so, then the
  73. most likely reason is that someone found yet another way to package
  74. Emacs (most likely on macOS) without putting the executable on ‘$PATH’,
  75. and we have to add another kludge to find it anyway.
  76. -- User Option: with-editor-emacsclient-executable
  77. The ‘emacsclient’ executable used as the editor by child process of
  78. this Emacs instance. By using this executable, child processes can
  79. call home to their parent process.
  80. This option is automatically set at startup by looking in
  81. ‘exec-path’, and other places where the executable could be
  82. installed, to find the ‘emacsclient’ executable most suitable for
  83. the current Emacs instance.
  84. You should *not* customize this option permanently. If you have to
  85. do it, then you should consider that a temporary kludge and inform
  86. the Magit maintainer as described in *note Debugging::.
  87. If With-Editor fails to find a suitable ‘emacsclient’ on you
  88. system, then this should be fixed for all users at once, by
  89. teaching ‘with-editor-locate-emacsclient’ how to do so on your
  90. system and system like yours. Doing it this way has the advantage,
  91. that you won’t have do it again every time you update Emacs, and
  92. that other users who have installed Emacs the same way as you have,
  93. won’t have to go through the same trouble.
  94. Note that there also is a nuclear option; setting this variable to
  95. ‘nil’ causes the "sleeping editor" described below to be used even
  96. for local child processes. Obviously we don’t recommend that you
  97. use this except in "emergencies", i.e. before we had a change to
  98. add a kludge appropriate for you setup.
  99. -- Function: with-editor-locate-emacsclient
  100. The function used to set the initial value of the option
  101. ‘with-editor-emacsclient-executable’. There’s a lot of voodoo
  102. here.
  103. The ‘emacsclient’ cannot be used when using Tramp to run a process on
  104. a remote machine. (Theoretically it could, but that would be hard to
  105. setup, very fragile, and rather insecure).
  106. With-Editor provides an alternative "editor" which can be used by
  107. remote processes in much the same way as local processes use an
  108. ‘emacsclient’ executable. This alternative is known as the "sleeping
  109. editor" because it is implemented as a shell script which sleeps until
  110. it receives a signal.
  111. -- User Option: with-editor-sleeping-editor
  112. The sleeping editor is a shell script used as the editor of child
  113. processes when the ‘emacsclient’ executable cannot be used.
  114. This fallback is used for asynchronous process started inside the
  115. macro ‘with-editor’, when the process runs on a remote machine or
  116. for local processes when ‘with-editor-emacsclient-executable’ is
  117. ‘nil’.
  118. Where the latter uses a socket to communicate with Emacs’ server,
  119. this substitute prints edit requests to its standard output on
  120. which a process filter listens for such requests. As such it is
  121. not a complete substitute for a proper ‘emacsclient’, it can only
  122. be used as ‘$EDITOR’ of child process of the current Emacs
  123. instance.
  124. Some shells do not execute traps immediately when waiting for a
  125. child process, but by default we do use such a blocking child
  126. process.
  127. If you use such a shell (e.g. ‘csh’ on FreeBSD, but not Debian),
  128. then you have to edit this option. You can either replace ‘sh’
  129. with ‘bash’ (and install that), or you can use the older, less
  130. performant implementation:
  131. "sh -c '\
  132. echo \"WITH-EDITOR: $$ OPEN $0 IN $(pwd)\"; \
  133. trap \"exit 0\" USR1; \
  134. trap \"exit 1\" USR2; \
  135. while true; do sleep 1; done'"
  136. Note that the unit separator character () right after the file name
  137. ($0) is required.
  138. Also note that using this alternative implementation leads to a
  139. delay of up to a second. The delay can be shortened by replacing
  140. ‘sleep 1’ with ‘sleep 0.01’, or if your implementation does not
  141. support floats, then by using ‘nanosleep’ instead.
  142. 
  143. File: with-editor.info, Node: Using With-Editor commands, Prev: Configuring With-Editor, Up: Using the With-Editor package
  144. 1.2 Using With-Editor commands
  145. ==============================
  146. This section describes how to use the ‘with-editor’ library _outside_ of
  147. Magit. You don’t need to know any of this just to create commits using
  148. Magit.
  149. The commands ‘with-editor-async-shell-command’ and
  150. ‘with-editor-shell-command’ are intended as drop in replacements for
  151. ‘async-shell-command’ and ‘shell-command’. They automatically export
  152. ‘$EDITOR’ making sure the executed command uses the current Emacs
  153. instance as "the editor". With a prefix argument these commands prompt
  154. for an alternative environment variable such as ‘$GIT_EDITOR’.
  155. -- Command: with-editor-async-shell-command
  156. This command is like ‘async-shell-command’, but it runs the shell
  157. command with the current Emacs instance exported as ‘$EDITOR’.
  158. -- Command: with-editor-shell-command
  159. This command is like ‘shell-command’, but if the shell command ends
  160. with ‘&’ and is therefore run asynchronously, then the current
  161. Emacs instance is exported as ‘$EDITOR’.
  162. To always use these variants add this to you init file:
  163. (define-key (current-global-map)
  164. [remap async-shell-command] 'with-editor-async-shell-command)
  165. (define-key (current-global-map)
  166. [remap shell-command] 'with-editor-shell-command)
  167. Alternatively use the global ‘shell-command-with-editor-mode’.
  168. -- Variable: shell-command-with-editor-mode
  169. When this mode is active, then ‘$EDITOR’ is exported whenever
  170. ultimately ‘shell-command’ is called to asynchronously run some
  171. shell command. This affects most variants of that command, whether
  172. they are defined in Emacs or in some third-party package.
  173. The command ‘with-editor-export-editor’ exports ‘$EDITOR’ or another
  174. such environment variable in ‘shell-mode’, ‘eshell-mode’, ‘term-mode’
  175. and ‘vterm-mode’ buffers. Use this Emacs command before executing a
  176. shell command which needs the editor set, or always arrange for the
  177. current Emacs instance to be used as editor by adding it to the
  178. appropriate mode hooks:
  179. (add-hook 'shell-mode-hook 'with-editor-export-editor)
  180. (add-hook 'eshell-mode-hook 'with-editor-export-editor)
  181. (add-hook 'term-exec-hook 'with-editor-export-editor)
  182. (add-hook 'vterm-exec-hook 'with-editor-export-editor)
  183. Some variants of this function exist; these two forms are equivalent:
  184. (add-hook 'shell-mode-hook
  185. (apply-partially 'with-editor-export-editor "GIT_EDITOR"))
  186. (add-hook 'shell-mode-hook 'with-editor-export-git-editor)
  187. -- Command: with-editor-export-editor
  188. When invoked in a ‘shell-mode’, ‘eshell-mode’, ‘term-mode’ or
  189. ‘vterm-mode’ buffer, this command teaches shell commands to use the
  190. current Emacs instance as the editor, by exporting ‘$EDITOR’.
  191. -- Command: with-editor-export-git-editor
  192. This command is like ‘with-editor-export-editor’ but exports
  193. ‘$GIT_EDITOR’.
  194. -- Command: with-editor-export-hg-editor
  195. This command is like ‘with-editor-export-editor’ but exports
  196. ‘$HG_EDITOR’.
  197. 
  198. File: with-editor.info, Node: Using With-Editor as a library, Next: Debugging, Prev: Using the With-Editor package, Up: Top
  199. 2 Using With-Editor as a library
  200. ********************************
  201. This section describes how to use the ‘with-editor’ library _outside_ of
  202. Magit to teach another package how to have its child processes call
  203. home, just like Magit does. You don’t need to know any of this just to
  204. create commits using Magit. You can also ignore this if you use
  205. ‘with-editor’ outside of Magit, but only as an end-user.
  206. For information about interactive use and options that affect both
  207. interactive and non-interactive use, see *note Using the With-Editor
  208. package::.
  209. -- Macro: with-editor &rest body
  210. This macro arranges for the ‘emacsclient’ or the sleeping editor to
  211. be used as the editor of child processes, effectively teaching them
  212. to call home to the current Emacs instance when they require that
  213. the user edits a file.
  214. This is done by establishing a local binding for
  215. ‘process-environment’ and changing the value of the ‘EDITOR’
  216. environment variable in that scope. This affects all
  217. (asynchronous) processes started by forms (dynamically) inside
  218. BODY.
  219. If BODY begins with a literal string, then that variable is set
  220. instead of ‘EDITOR’.
  221. -- Macro: with-editor envvar &rest body
  222. This macro is like ‘with-editor’ instead that the ENVVAR argument
  223. is required and that it is evaluated at run-time.
  224. -- Function: with-editor-set-process-filter process filter
  225. This function is like ‘set-process-filter’ but ensures that adding
  226. the new FILTER does not remove the ‘with-editor-process-filter’.
  227. This is done by wrapping the two filter functions using a lambda,
  228. which becomes the actual filter. It calls
  229. ‘with-editor-process-filter’ first, passing ‘t’ as
  230. NO-STANDARD-FILTER. Then it calls FILTER.
  231. 
  232. File: with-editor.info, Node: Debugging, Next: Command Index, Prev: Using With-Editor as a library, Up: Top
  233. 3 Debugging
  234. ***********
  235. With-Editor tries very hard to locate a suitable ‘emacsclient’
  236. executable, and then sets option ‘with-editor-emacsclient-executable’
  237. accordingly. In very rare cases this fails. When it does fail, then
  238. the most likely reason is that someone found yet another way to package
  239. Emacs (most likely on macOS) without putting the executable on ‘$PATH’,
  240. and we have to add another kludge to find it anyway.
  241. If you are having problems using ‘with-editor’, e.g. you cannot
  242. commit in Magit, then please open a new issue at
  243. <https://github.com/magit/with-editor/issues> and provide information
  244. about your Emacs installation. Most importantly how did you install
  245. Emacs and what is the output of ‘M-x with-editor-debug RET’.
  246. 
  247. File: with-editor.info, Node: Command Index, Next: Function Index, Prev: Debugging, Up: Top
  248. Appendix A Command Index
  249. ************************
  250. [index]
  251. * Menu:
  252. * with-editor-async-shell-command: Using With-Editor commands.
  253. (line 17)
  254. * with-editor-export-editor: Using With-Editor commands.
  255. (line 62)
  256. * with-editor-export-git-editor: Using With-Editor commands.
  257. (line 68)
  258. * with-editor-export-hg-editor: Using With-Editor commands.
  259. (line 73)
  260. * with-editor-shell-command: Using With-Editor commands.
  261. (line 22)
  262. 
  263. File: with-editor.info, Node: Function Index, Next: Variable Index, Prev: Command Index, Up: Top
  264. Appendix B Function Index
  265. *************************
  266. [index]
  267. * Menu:
  268. * with-editor: Using With-Editor as a library.
  269. (line 16)
  270. * with-editor <1>: Using With-Editor as a library.
  271. (line 32)
  272. * with-editor-async-shell-command: Using With-Editor commands.
  273. (line 17)
  274. * with-editor-export-editor: Using With-Editor commands.
  275. (line 62)
  276. * with-editor-export-git-editor: Using With-Editor commands.
  277. (line 68)
  278. * with-editor-export-hg-editor: Using With-Editor commands.
  279. (line 73)
  280. * with-editor-locate-emacsclient: Configuring With-Editor.
  281. (line 42)
  282. * with-editor-set-process-filter: Using With-Editor as a library.
  283. (line 37)
  284. * with-editor-shell-command: Using With-Editor commands.
  285. (line 22)
  286. 
  287. File: with-editor.info, Node: Variable Index, Prev: Function Index, Up: Top
  288. Appendix C Variable Index
  289. *************************
  290. [index]
  291. * Menu:
  292. * shell-command-with-editor-mode: Using With-Editor commands.
  293. (line 37)
  294. * with-editor-emacsclient-executable: Configuring With-Editor.
  295. (line 13)
  296. * with-editor-sleeping-editor: Configuring With-Editor.
  297. (line 58)
  298. 
  299. Tag Table:
  300. Node: Top773
  301. Node: Using the With-Editor package2569
  302. Node: Configuring With-Editor3155
  303. Node: Using With-Editor commands7704
  304. Node: Using With-Editor as a library10995
  305. Node: Debugging12958
  306. Node: Command Index13837
  307. Node: Function Index14719
  308. Node: Variable Index16185
  309. 
  310. End Tag Table
  311. 
  312. Local Variables:
  313. coding: utf-8
  314. End: