File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,16 @@ These scripts are aimed at developers and provide useful utilities for working w
88
88
89
89
* ** jj-undirty.el:** A simple Emacs lisp script that automatically runs ` jj status ` every time a buffer is saved to snapshot file modifications.
90
90
` Usage: (load (expand-file-name "~/jj-fzf/contrib/jj-undirty.el")) `
91
+ This will install an after-save-hook that calls ` jj-undirty ` to snapshot the changes in a saved buffer in a jj repository.
92
+
93
+ * ** suspend-with-shell.el:** A simple Emacs lisp script that allows to suspend Emacs with a custom command.
94
+ ```
95
+ Usage:
96
+ ;; Suspend emacs with a custom command, without using `ioctl(TIOCSTI)`
97
+ (load (expand-file-name "~/jj-fzf/contrib/suspend-with-shell.el"))
98
+ ;; Suspend emacs and start jj-fzf on Ctrl+T
99
+ (global-set-key (kbd "C-t") (lambda () (interactive) (suspend-with-shell "jj-fzf")))
100
+ ```
91
101
92
102
<!-- LICENSE -->
93
103
## License
Original file line number Diff line number Diff line change
1
+ ; ; This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2
+
3
+ ; ; == suspend-with-shell ==
4
+ ; ; Wrap `(suspend-emacs)` so that a subshell is executed with $SHELL pointing
5
+ ; ; to a script that will run `COMMAND`. This way, emacs can be suspended
6
+ ; ; to run another terminal process on the same tty, without using
7
+ ; ; `ioctl(TIOCSTI)` - which `(suspend-emacs)` relies on but is not available
8
+ ; ; in recent kernel versions.
9
+ (defun suspend-with-shell (COMMAND )
10
+ " Call (suspend-emacs) with $SHELL assigned to a script that will run COMMAND"
11
+ (interactive )
12
+ (let ((oldshell (getenv " SHELL" ))
13
+ (tfile (make-temp-file " emacssubshell" ))
14
+ (script (concat " #!/usr/bin/env bash\n set -Eeu #-x\n " COMMAND " \n " ))
15
+ (cannot-suspend 't )) ; force suspend-emacs to use sys_subshell
16
+ (with-temp-file tfile
17
+ (insert script))
18
+ (set-file-modes tfile #o700 'nofollow )
19
+ ; ; see sys_subshell() in https://github.com/emacs-mirror/emacs/blob/master/src/keyboard.c
20
+ (setenv " SHELL" tfile)
21
+ (suspend-emacs ) ; this calls system($SHELL)
22
+ (setenv " SHELL" oldshell)
23
+ (delete-file tfile)
24
+ )
25
+ )
You can’t perform that action at this time.
0 commit comments