lem-project / lem

Common Lisp editor/IDE with high expansibility
http://lem-project.github.io/
MIT License
2.4k stars 178 forks source link

Allow Ctrl+z to temporarily suspend lem #306

Closed carrotflakes closed 2 years ago

carrotflakes commented 6 years ago

I want to move lem process to background, like emacs.

appetrosyan commented 2 years ago

I would encourage not doing this by default. lem doesn't need to carry the whole baggage of emacs.

cxxxr commented 2 years ago

I'll close this issue once 🙏

fukamachi commented 1 year ago

This is not an Emacs-specific feature. Most applications running in a shell follow this convention. Vim/Neovim also allows users to suspend it temporarily, and I think it's quite useful to access the full shell.

Perhaps it can be omitted if Lem has a complete shell-mode, though.

fukamachi commented 1 year ago

This is a workaround to do in ~/lem/init.lisp:

(define-command suspend-lem () ()
  (charms/ll:endwin)
  (uiop:launch-program `("kill" "-TSTP" ,(princ-to-string (sb-posix:getpid)))))

(define-key *global-keymap* "C-z" 'suspend-lem)

It fails randomly about 1 in 20 times because ncurses's wgetch blocks signals from SBCL. It can be solved by wrapping it by sb-sys:without-interrupts, but it will introduce another small inconvenience when quitting Lem.

diff --git a/frontends/ncurses/ncurses.lisp b/frontends/ncurses/ncurses.lisp
index 628d487c..31d0e295 100644
--- a/frontends/ncurses/ncurses.lisp
+++ b/frontends/ncurses/ncurses.lisp
@@ -107,7 +107,8 @@
     (setf *padwin* (charms/ll:newpad 1 1))
     (charms/ll:keypad *padwin* 1)
     (charms/ll:wtimeout *padwin* -1))
-  (charms/ll:wgetch *padwin*))
+  (sb-sys:with-interrupts
+    (charms/ll:wgetch *padwin*)))
 (defmacro with-getch-input-timeout ((time) &body body)
   `(progn
      (charms/ll:wtimeout *padwin* ,time)
fukamachi commented 1 year ago

I found this works perfectly without any problems. I added this to my init.lisp.

(define-command suspend-lem () ()
  (charms/ll:endwin)
  (sb-posix:kill (sb-posix:getpid) sb-posix:sigtstp))

(define-key *global-keymap* "C-z" 'suspend-lem)
vindarel commented 11 months ago

charms/ll doesn't exist when we run the SDL2 GUI, so we can do:

(define-command suspend-lem () ()
  (when (find-package 'charms/ll)
    (uiop:symbol-call 'charms/ll 'endwin)
    (sb-posix:kill (sb-posix:getpid) sb-posix:sigtstp)))
fukamachi commented 11 months ago

Good point. I run it only on lem-ncurses like: https://github.com/fukamachi/.lem/blob/master/init.lisp#L21-L27

vindarel commented 11 months ago

oh, with:

#+(and lem-ncurses (not (and darwin arm64)))

that's better.