Close emacs when view/mode is closed

This commit is contained in:
2025-09-09 07:32:07 +02:00
parent 7cc80e8cf4
commit 8567e48c4c
5 changed files with 66 additions and 2 deletions

View File

@@ -3,5 +3,13 @@
EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn
(require 'elfeed nil t)
;; Quit Emacs when q is pressed in elfeed
(add-hook 'elfeed-search-mode-hook
(lambda ()
;; Override the quit behavior to exit Emacs
(local-set-key (kbd \"q\")
(lambda ()
(interactive)
(kill-emacs)))))
(elfeed)
(elfeed-update))"

View File

@@ -11,6 +11,14 @@ if [ $# -eq 0 ]; then
(package-refresh-contents)
(package-install 'magit))
(require 'magit)
;; Quit Emacs when magit status buffer is killed
(add-hook 'magit-status-mode-hook
(lambda ()
(add-hook 'kill-buffer-hook
(lambda ()
(when (eq major-mode 'magit-status-mode)
(kill-emacs)))
nil t)))
(magit-status))"
else
# Use specified directory
@@ -25,5 +33,13 @@ else
(package-refresh-contents)
(package-install 'magit))
(require 'magit)
;; Quit Emacs when magit status buffer is killed
(add-hook 'magit-status-mode-hook
(lambda ()
(add-hook 'kill-buffer-hook
(lambda ()
(when (eq major-mode 'magit-status-mode)
(kill-emacs)))
nil t)))
(magit-status))"
fi

View File

@@ -3,4 +3,12 @@
EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn
(require 'mu4e nil t)
;; Quit Emacs when mu4e main buffer is killed
(add-hook 'mu4e-main-mode-hook
(lambda ()
(add-hook 'kill-buffer-hook
(lambda ()
(when (eq major-mode 'mu4e-main-mode)
(kill-emacs)))
nil t)))
(mu4e))"

View File

@@ -6,15 +6,38 @@ if [ $# -eq 0 ]; then
# No arguments, start with org-agenda
EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn
(require 'org)
;; Quit Emacs when org-agenda buffer is killed
(add-hook 'org-agenda-mode-hook
(lambda ()
(add-hook 'kill-buffer-hook
(lambda ()
(when (eq major-mode 'org-agenda-mode)
(kill-emacs)))
nil t)))
(org-agenda))"
else
# Open specified org file
if [ -f "$1" ]; then
EMACS_NO_DESKTOP=1 emacs -nw "$1" --eval "(org-mode)"
EMACS_NO_DESKTOP=1 emacs -nw "$1" --eval "(progn
(org-mode)
;; Quit Emacs when this org file buffer is killed
(add-hook 'kill-buffer-hook
(lambda ()
(when (and (eq major-mode 'org-mode)
(= (length (buffer-list)) 2))
(kill-emacs)))
nil t))"
else
# Create new org file
EMACS_NO_DESKTOP=1 emacs -nw "$1" --eval "(progn
(org-mode)
(insert \"#+TITLE: $(basename \"$1\" .org)\n#+DATE: $(date +%Y-%m-%d)\n\n\"))"
(insert \"#+TITLE: $(basename \"$1\" .org)\n#+DATE: $(date +%Y-%m-%d)\n\n\")
;; Quit Emacs when this org file buffer is killed
(add-hook 'kill-buffer-hook
(lambda ()
(when (and (eq major-mode 'org-mode)
(= (length (buffer-list)) 2))
(kill-emacs)))
nil t))"
fi
fi

View File

@@ -3,4 +3,13 @@
EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn
(when (fboundp 'portfolio-tracker)
;; Quit Emacs when portfolio tracker buffer is killed
(add-hook 'tabulated-list-mode-hook
(lambda ()
(when (string-match-p \"\\*Portfolio Tracker\\*\" (buffer-name))
(add-hook 'kill-buffer-hook
(lambda ()
(when (string-match-p \"\\*Portfolio Tracker\\*\" (buffer-name))
(kill-emacs)))
nil t))))
(portfolio-tracker)))"