From 6eb0161f8ed3b869aa402806b352505dc754c72e Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sun, 12 Mar 2023 12:07:09 -0400 Subject: config --- emacs/.config/emacs-kj/init.el | 116 ++++------------------------- emacs/.config/emacs-kj/lisp/kj-bindings.el | 20 +++++ emacs/.config/emacs-kj/lisp/kj-popup.el | 83 +++++++++++++++++++++ 3 files changed, 118 insertions(+), 101 deletions(-) create mode 100644 emacs/.config/emacs-kj/lisp/kj-bindings.el create mode 100644 emacs/.config/emacs-kj/lisp/kj-popup.el (limited to 'emacs/.config') diff --git a/emacs/.config/emacs-kj/init.el b/emacs/.config/emacs-kj/init.el index 3658e63..bbc6640 100644 --- a/emacs/.config/emacs-kj/init.el +++ b/emacs/.config/emacs-kj/init.el @@ -702,22 +702,6 @@ (kill-region (region-beginning) (region-end)) (backward-kill-word (or arg 1)))) -(use-package emacs - :bind - (("C-w" . kj/kill-word-or-region) - ("C-c d" . kill-region) - ("C-c m" . smerge-ediff) - ("C-c b r" . revert-buffer) - ("C-c r l" . consult-flymake) - ("C-c r f" . eglot-format) - ("C-c r g" . recompile) - ("C-c r a" . eglot-code-actions) - ("C-c r r" . eglot-rename) - ("C-c c i" . insert-char) - ("C-c w u" . winner-undo) - ("C-c w U" . winner-redo) - ("C-" . completion-at-point))) - (let ((google-config-file (expand-file-name "google.el" user-emacs-directory))) (when (file-exists-p google-config-file) @@ -773,93 +757,23 @@ (previous-line kj/some-lines)) ;; Repeat commands (e.g., C-x o o o) -;; (use-package repeat-help -;; :ensure t ;; or :straight t -;; :hook (repeat-mode . repeat-help-mode) -;; :config -;; (setq repeat-help-popup-type "which-key")) (repeat-mode 1) -;;; Window placement -;;; TODO: Test popper.el. -(global-set-key (kbd "C-`") #'window-toggle-side-windows) -(global-set-key (kbd "M-`") #'kj/popup-toggle-override) -(setq window-sides-slots '(0 0 2 2)) ; 2 right side windows -(setq switch-to-buffer-obey-display-actions t) -(setq switch-to-buffer-in-dedicated-window 'pop) - -(defvar kj/popup-override nil) - -(defun kj/popup-clear-overrides () - (interactive) - (dolist (buffer (buffer-list)) - (with-current-buffer buffer - (kill-local-variable 'kj/popup-override)))) - -(defun kj/popup-toggle-override () - (interactive) - (if (local-variable-p 'kj/popup-override) - (kill-local-variable 'kj/popup-override) - (setq-local kj/popup-override - (not (kj/popup-buffer-base (buffer-name))))) - (let ((buffer (buffer-name))) - (switch-to-prev-buffer) - (switch-to-buffer buffer))) - -(defun kj/popup-buffer-base (buffer &optional condition) - (or - (s-matches-p - (rx (| "*Help*" - "*info*" - (seq "*scratch*") - (seq "*Messages*") - (seq "*Warnings*") - (seq "*Backtrace*") - (seq "*eldoc " (* anything) "*") - (seq "*WoMan " (* anything) "*") - (seq "*man " (* anything) "*") - (seq "fig: " (* anything)) - (seq "*htop*" (* anything)) - (seq "*Proced*" (* anything)) - (seq "*eshell*" (* anything)) - (seq "*shell*" (* anything)) - "*Occur*")) buffer) - (with-current-buffer buffer - (apply #'derived-mode-p - '(magit-mode - compilation-mode - shell-mode - comint-mode - Custom-mode ; For customization - fig-commit-mode))))) - -(defun kj/popup-buffer (buffer &optional condition) - (with-current-buffer buffer - (if (local-variable-p 'kj/popup-override) - kj/popup-override - (kj/popup-buffer-base buffer condition)))) - -(setq transient-display-buffer-action - '(display-buffer-in-best-side - (slot . 1) - (inhibit-same-window . t) - (window-parameters - (no-other-window . t)))) - -(defun display-buffer-in-best-side (buffer alist) - (display-buffer-in-side-window - buffer - (append (if (> (frame-width) 160) - '((side . right) - (window-width . 85)) - '((side . bottom) - (window-height . 0.5))) - alist))) - -(add-to-list 'display-buffer-alist - `(kj/popup-buffer - (display-buffer-in-best-side) - (slot . 0))) +;; Disable the built-in repeat-mode hinting +(setq repeat-echo-function #'ignore) + +;; Spawn or hide a which-key popup +(advice-add 'repeat-post-hook :after + (defun repeat-help--which-key-popup () + (if-let ((cmd (or this-command real-this-command)) + (keymap (or repeat-map + (repeat--command-property 'repeat-map)))) + (run-at-time + 0 nil + (lambda () + (which-key--create-buffer-and-show + nil (symbol-value keymap)))) + (which-key--hide-popup)))) ;; Calendar settings. (setq calendar-week-start-day 1) diff --git a/emacs/.config/emacs-kj/lisp/kj-bindings.el b/emacs/.config/emacs-kj/lisp/kj-bindings.el new file mode 100644 index 0000000..37332f2 --- /dev/null +++ b/emacs/.config/emacs-kj/lisp/kj-bindings.el @@ -0,0 +1,20 @@ +;;; -*- lexical-binding: t; -*- + +(use-package emacs + :bind + (("C-w" . kj/kill-word-or-region) + ("C-c s" . shell) + ("C-c e" . eshell) + ("C-c m" . smerge-ediff) + ("C-c b r" . revert-buffer) + ("C-c r l" . consult-flymake) + ("C-c r f" . eglot-format) + ("C-c r g" . recompile) + ("C-c r a" . eglot-code-actions) + ("C-c r r" . eglot-rename) + ("C-c c i" . insert-char) + ("C-c w u" . winner-undo) + ("C-c w U" . winner-redo) + ("C-" . completion-at-point))) + +(provide 'kj-bindings) diff --git a/emacs/.config/emacs-kj/lisp/kj-popup.el b/emacs/.config/emacs-kj/lisp/kj-popup.el new file mode 100644 index 0000000..6bda93d --- /dev/null +++ b/emacs/.config/emacs-kj/lisp/kj-popup.el @@ -0,0 +1,83 @@ +;;; -*- lexical-binding: t; -*- +;;; Window placement +;;; TODO: Test popper.el. +(global-set-key (kbd "C-`") #'window-toggle-side-windows) +(global-set-key (kbd "M-`") #'kj/popup-toggle-override) +(setq window-sides-slots '(0 0 2 2)) ; 2 right side windows +(setq switch-to-buffer-obey-display-actions t) +(setq switch-to-buffer-in-dedicated-window 'pop) + +(defvar kj/popup-override nil) + +(defun kj/popup-clear-overrides () + (interactive) + (dolist (buffer (buffer-list)) + (with-current-buffer buffer + (kill-local-variable 'kj/popup-override)))) + +(defun kj/popup-toggle-override () + (interactive) + (if (local-variable-p 'kj/popup-override) + (kill-local-variable 'kj/popup-override) + (setq-local kj/popup-override + (not (kj/popup-buffer-base (buffer-name))))) + (let ((buffer (buffer-name))) + (switch-to-prev-buffer) + (switch-to-buffer buffer))) + +(defun kj/popup-buffer-base (buffer &optional condition) + (or + (s-matches-p + (rx (| "*Help*" + "*info*" + (seq "*scratch*") + (seq "*Messages*") + (seq "*Warnings*") + (seq "*Backtrace*") + (seq "*eldoc " (* anything) "*") + (seq "*WoMan " (* anything) "*") + (seq "*man " (* anything) "*") + (seq "fig: " (* anything)) + (seq "*htop*" (* anything)) + (seq "*Proced*" (* anything)) + (seq "*eshell*" (* anything)) + (seq "*shell*" (* anything)) + "*Occur*")) buffer) + (with-current-buffer buffer + (apply #'derived-mode-p + '(magit-mode + compilation-mode + shell-mode + comint-mode + Custom-mode ; For customization + fig-commit-mode))))) + +(defun kj/popup-buffer (buffer &optional condition) + (with-current-buffer buffer + (if (local-variable-p 'kj/popup-override) + kj/popup-override + (kj/popup-buffer-base buffer condition)))) + +(setq transient-display-buffer-action + '(display-buffer-in-best-side + (slot . 1) + (inhibit-same-window . t) + (window-parameters + (no-other-window . t)))) + +(defun display-buffer-in-best-side (buffer alist) + (display-buffer-in-side-window + buffer + (append (if (> (frame-width) 160) + '((side . right) + (window-width . 85)) + '((side . bottom) + (window-height . 0.5))) + alist))) + +(add-to-list 'display-buffer-alist + `(kj/popup-buffer + (display-buffer-in-best-side) + (slot . 0))) + +(provide 'kj-popup) -- cgit v1.2.3