Klimi's new dotfiles with stow.
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.

343 lines
14 KiB

4 years ago
  1. This is with-editor.info, produced by makeinfo version 6.5 from
  2. with-editor.texi.
  3. Copyright (C) 2015-2019 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 2.8.3.
  33. Copyright (C) 2015-2019 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. — The Detailed Node Listing —
  47. Using the With-Editor package
  48. * Configuring With-Editor::
  49. * Using With-Editor commands::
  50. 
  51. File: with-editor.info, Node: Using the With-Editor package, Next: Using With-Editor as a library, Prev: Top, Up: Top
  52. 1 Using the With-Editor package
  53. *******************************
  54. The ‘With-Editor’ package is used internally by Magit when editing
  55. commit messages and rebase sequences. It also provides some commands
  56. and features which are useful by themselves, even if you don’t use
  57. Magit.
  58. For information about using this library in you own package, see
  59. *note Using With-Editor as a library::.
  60. * Menu:
  61. * Configuring With-Editor::
  62. * Using With-Editor commands::
  63. 
  64. File: with-editor.info, Node: Configuring With-Editor, Next: Using With-Editor commands, Up: Using the With-Editor package
  65. 1.1 Configuring With-Editor
  66. ===========================
  67. With-Editor tries very hard to locate a suitable ‘emacsclient’
  68. executable, so ideally you should never have to customize the option
  69. ‘with-editor-emacsclient-executable’. When it fails to do so, then the
  70. most likely reason is that someone found yet another way to package
  71. Emacs (most likely on macOS) without putting the executable on ‘$PATH’,
  72. and we have to add another kludge to find it anyway.
  73. -- User Option: with-editor-emacsclient-executable
  74. The ‘emacsclient’ executable used as the editor by child process of
  75. this Emacs instance. By using this executable, child processes can
  76. call home to their parent process.
  77. This option is automatically set at startup by looking in
  78. ‘exec-path’, and other places where the executable could be
  79. installed, to find the ‘emacsclient’ executable most suitable for
  80. the current Emacs instance.
  81. You should *not* customize this option permanently. If you have to
  82. do it, then you should consider that a temporary kludge and inform
  83. the Magit maintainer as described in *note Debugging::.
  84. If With-Editor fails to find a suitable ‘emacsclient’ on you
  85. system, then this should be fixed for all users at once, by
  86. teaching ‘with-editor-locate-emacsclient’ how to do so on your
  87. system and system like yours. Doing it this way has the advantage,
  88. that you won’t have do it again every time you update Emacs, and
  89. that other users who have installed Emacs the same way as you have,
  90. won’t have to go through the same trouble.
  91. Note that there also is a nuclear option; setting this variable to
  92. ‘nil’ causes the "sleeping editor" described below to be used even
  93. for local child processes. Obviously we don’t recommend that you
  94. use this except in "emergencies", i.e. before we had a change to
  95. add a kludge appropriate for you setup.
  96. -- Function: with-editor-locate-emacsclient
  97. The function used to set the initial value of the option
  98. ‘with-editor-emacsclient-executable’. There’s a lot of voodoo
  99. here.
  100. The ‘emacsclient’ cannot be used when using Tramp to run a process on
  101. a remote machine. (Theoretically it could, but that would be hard to
  102. setup, very fragile, and rather insecure).
  103. With-Editor provides an alternative "editor" which can be used by
  104. remote processes in much the same way as local processes use an
  105. ‘emacsclient’ executable. This alternative is known as the "sleeping
  106. editor" because it is implemented as a shell script which sleeps until
  107. it receives a signal.
  108. -- User Option: with-editor-sleeping-editor
  109. The sleeping editor is a shell script used as the editor of child
  110. processes when the ‘emacsclient’ executable cannot be used.
  111. This fallback is used for asynchronous process started inside the
  112. macro ‘with-editor’, when the process runs on a remote machine or
  113. for local processes when ‘with-editor-emacsclient-executable’ is
  114. ‘nil’.
  115. Where the latter uses a socket to communicate with Emacs’ server,
  116. this substitute prints edit requests to its standard output on
  117. which a process filter listens for such requests. As such it is
  118. not a complete substitute for a proper ‘emacsclient’, it can only
  119. be used as ‘$EDITOR’ of child process of the current Emacs
  120. instance.
  121. Some shells do not execute traps immediately when waiting for a
  122. child process, but by default we do use such a blocking child
  123. process.
  124. If you use such a shell (e.g. ‘csh’ on FreeBSD, but not Debian),
  125. then you have to edit this option. You can either replace ‘sh’
  126. with ‘bash’ (and install that), or you can use the older, less
  127. performant implementation:
  128. "sh -c '\
  129. echo \"WITH-EDITOR: $$ OPEN $0 IN $(pwd)\"; \
  130. trap \"exit 0\" USR1; \
  131. trap \"exit 1\" USR2; \
  132. while true; do sleep 1; done'"
  133. Note that the unit seperator character () right after the file name
  134. ($0) is required.
  135. Also note that using this alternative implementation leads to a
  136. delay of up to a second. The delay can be shortened by replacing
  137. ‘sleep 1’ with ‘sleep 0.01’, or if your implementation does not
  138. support floats, then by using ‘nanosleep’ instead.
  139. 
  140. File: with-editor.info, Node: Using With-Editor commands, Prev: Configuring With-Editor, Up: Using the With-Editor package
  141. 1.2 Using With-Editor commands
  142. ==============================
  143. This section describes how to use the ‘with-editor’ library _outside_ of
  144. Magit. You don’t need to know any of this just to create commits using
  145. Magit.
  146. The commands ‘with-editor-async-shell-command’ and
  147. ‘with-editor-shell-command’ are intended as drop in replacements for
  148. ‘async-shell-command’ and ‘shell-command’. They automatically export
  149. ‘$EDITOR’ making sure the executed command uses the current Emacs
  150. instance as "the editor". With a prefix argument these commands prompt
  151. for an alternative environment variable such as ‘$GIT_EDITOR’.
  152. -- Command: with-editor-async-shell-command
  153. This command is like ‘async-shell-command’, but it runs the shell
  154. command with the current Emacs instance exported as ‘$EDITOR’.
  155. -- Command: with-editor-shell-command
  156. This command is like ‘shell-command’, but if the shell command ends
  157. with ‘&’ and is therefore run asynchronously, then the current
  158. Emacs instance is exported as ‘$EDITOR’.
  159. To always use these variants add this to you init file:
  160. (define-key (current-global-map)
  161. [remap async-shell-command] 'with-editor-async-shell-command)
  162. (define-key (current-global-map)
  163. [remap shell-command] 'with-editor-shell-command)
  164. Alternatively use the global ‘shell-command-with-editor-mode’.
  165. -- Variable: shell-command-with-editor-mode
  166. When this mode is active, then ‘$EDITOR’ is exported whenever
  167. ultimately ‘shell-command’ is called to asynchronously run some
  168. shell command. This affects most variants of that command, whether
  169. they are defined in Emacs or in some third-party package.
  170. The command ‘with-editor-export-editor’ exports ‘$EDITOR’ or another
  171. such environment variable in ‘shell-mode’, ‘term-mode’ and ‘eshell-mode’
  172. buffers. Use this Emacs command before executing a shell command which
  173. needs the editor set, or always arrange for the current Emacs instance
  174. to be used as editor by adding it to the appropriate mode hooks:
  175. (add-hook 'shell-mode-hook 'with-editor-export-editor)
  176. (add-hook 'term-exec-hook 'with-editor-export-editor)
  177. (add-hook 'eshell-mode-hook 'with-editor-export-editor)
  178. Some variants of this function exist; these two forms are equivalent:
  179. (add-hook 'shell-mode-hook
  180. (apply-partially 'with-editor-export-editor "GIT_EDITOR"))
  181. (add-hook 'shell-mode-hook 'with-editor-export-git-editor)
  182. -- Command: with-editor-export-editor
  183. When invoked in a ‘shell-mode’, ‘term-mode’, or ‘eshell-mode’
  184. buffer, this command teaches shell commands to use the current
  185. Emacs instance as the editor, by exporting ‘$EDITOR’.
  186. -- Command: with-editor-export-git-editor
  187. This command is like ‘with-editor-export-editor’ but exports
  188. ‘$GIT_EDITOR’.
  189. -- Command: with-editor-export-hg-editor
  190. This command is like ‘with-editor-export-editor’ but exports
  191. ‘$HG_EDITOR’.
  192. 
  193. File: with-editor.info, Node: Using With-Editor as a library, Next: Debugging, Prev: Using the With-Editor package, Up: Top
  194. 2 Using With-Editor as a library
  195. ********************************
  196. This section describes how to use the ‘with-editor’ library _outside_ of
  197. Magit to teach another package how to have its child processes call
  198. home, just like Magit does. You don’t need to know any of this just to
  199. create commits using Magit. You can also ignore this if you use
  200. ‘with-editor’ outside of Magit, but only as an end-user.
  201. For information about interactive use and options that affect both
  202. interactive and non-interactive use, see *note Using the With-Editor
  203. package::.
  204. -- Macro: with-editor &rest body
  205. This macro arranges for the ‘emacsclient’ or the sleeping editor to
  206. be used as the editor of child processes, effectively teaching them
  207. to call home to the current Emacs instance when they require that
  208. the user edits a file.
  209. This is done by establishing a local binding for
  210. ‘process-environment’ and changing the value of the ‘EDITOR’
  211. environment variable in that scope. This affects all
  212. (asynchronous) processes started by forms (dynamically) inside
  213. BODY.
  214. If BODY begins with a literal string, then that variable is set
  215. instead of ‘EDITOR’.
  216. -- Macro: with-editor envvar &rest body
  217. This macro is like ‘with-editor’ instead that the ENVVAR argument
  218. is required and that it is evaluated at run-time.
  219. -- Function: with-editor-set-process-filter process filter
  220. This function is like ‘set-process-filter’ but ensures that adding
  221. the new FILTER does not remove the ‘with-editor-process-filter’.
  222. This is done by wrapping the two filter functions using a lambda,
  223. which becomes the actual filter. It calls
  224. ‘with-editor-process-filter’ first, passing ‘t’ as
  225. NO-STANDARD-FILTER. Then it calls FILTER.
  226. 
  227. File: with-editor.info, Node: Debugging, Prev: Using With-Editor as a library, Up: Top
  228. 3 Debugging
  229. ***********
  230. With-Editor tries very hard to locate a suitable ‘emacsclient’
  231. executable, and then sets option ‘with-editor-emacsclient-executable’
  232. accordingly. In very rare cases this fails. When it does fail, then
  233. the most likely reason is that someone found yet another way to package
  234. Emacs (most likely on macOS) without putting the executable on ‘$PATH’,
  235. and we have to add another kludge to find it anyway.
  236. If you are having problems using ‘with-editor’, e.g. you cannot
  237. commit in Magit, then please open a new issue at
  238. <https://github.com/magit/with-editor/issues> and provide information
  239. about your Emacs installation. Most importantly how did you install
  240. Emacs and what is the output of ‘M-x with-editor-debug RET’.
  241. 
  242. Tag Table:
  243. Node: Top773
  244. Node: Using the With-Editor package2513
  245. Node: Configuring With-Editor3099
  246. Node: Using With-Editor commands7648
  247. Node: Using With-Editor as a library10843
  248. Node: Debugging12806
  249. 
  250. End Tag Table
  251. 
  252. Local Variables:
  253. coding: utf-8
  254. End: