From d10dae9bfb03890b3e2bc42e59279b5f4c70dc86 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Mon, 27 Feb 2023 18:32:10 +0700 Subject: [PATCH] Got popper working --- .config/emacs/init.org | 145 +++++++++++++++++++++------------- .config/fish/functions/e.fish | 2 +- 2 files changed, 93 insertions(+), 54 deletions(-) diff --git a/.config/emacs/init.org b/.config/emacs/init.org index ff017c3..955ef07 100644 --- a/.config/emacs/init.org +++ b/.config/emacs/init.org @@ -73,6 +73,8 @@ Prioritize old byte-compiled source files over newer sources. It saves us a litt (org-babel-tangle)) nil t))) +(setq server-name (format "Emacs-%d" (emacs-pid))) +(add-hook 'after-init-hook #'server-start) #+end_src *** UTF-8 Support #+begin_src emacs-lisp :tangle ./early-init.el @@ -229,9 +231,9 @@ Save the chosen theme after picking a new one (let ((inhibit-message t) (message-log-max nil)) (customize-save-variable 'custom-enabled-themes custom-enabled-themes))) -;; (add-hook 'kill-emacs-hook #'joe/save-current-theme) (advice-add 'consult-theme :after #'joe/save-current-theme) -(advice-remove 'load-theme 'joe/save-current-theme) + +;; (advice-remove 'load-theme 'joe/save-current-theme) #+end_src *** Other @@ -592,7 +594,7 @@ weren't working, until I randomly saw this in someone's init.el ;; (define-key evil-consult-map "c" 'evil-window-delete) (defvar global-evil-leader-map (make-sparse-keymap)) -(evil-define-key 'normal 'global-evil-leader-map (kbd "SPC") 'evil-send-leader) +;; (evil-define-key 'normal 'global-evil-leader-map (kbd "SPC") 'evil-send-leader) (define-minor-mode global-evil-leader-mode "Minor mode to make evil leader global" @@ -677,10 +679,9 @@ The theme of `C-x 4` bindings is that they operate on other windows, so this fun #+begin_src emacs-lisp (add-hook 'after-init-hook (lambda () (winner-mode t))) -(straight-use-package 'rotate) (setq joe/popper-side-toggle 'right) -(defun joe/window-split-vertical () (interactive) (set 'joe/popper-side-toggle 'right) (rotate:main-horizontal)) -(defun joe/window-split-horizontal () (interactive) (set 'joe/popper-side-toggle 'below) (rotate:main-vertical)) +(defun joe/window-split-vertical () (interactive) (set 'joe/popper-side-toggle 'right)) +(defun joe/window-split-horizontal () (interactive) (set 'joe/popper-side-toggle 'below)) (define-key ctl-x-4-map (kbd "|") #'joe/window-split-vertical) (define-key ctl-x-4-map (kbd "-") #'joe/window-split-horizontal) @@ -716,7 +717,7 @@ The theme of `C-x 4` bindings is that they operate on other windows, so this fun helpful-mode)) (global-set-key (kbd "C-`") 'popper-toggle-latest) -(global-set-key (kbd "C-~") 'popper-cycle) +(global-set-key (kbd "C-~") 'popper-cycle) (global-set-key (kbd "C-M-`") 'popper-toggle-type) (require 'popper-echo) (popper-echo-mode t) @@ -730,13 +731,26 @@ The theme of `C-x 4` bindings is that they operate on other windows, so this fun ;; TODO Consider adding checks for vertical splits and only popup on right if so (defun joe/popper-display-func (buffer &optional _alist) (cond - ((cl-find-if - (lambda (window) - (with-current-buffer (window-buffer window) popper-popup-status)) - (window-list)) - (display-buffer-reuse-window - buffer - `((body-function . ,#'select-window)))) + ((when-let ((popup-buffer + (cl-find-if + #'popper-popup-p + (mapcar #'window-buffer (window-list))))) + (window--display-buffer + buffer (get-buffer-window popup-buffer) 'reuse + `((body-function . ,#'select-window))))) + + ((and (eq joe/popper-side-toggle 'right) + (window-in-direction 'left)) + (message "Here") + (window--display-buffer + buffer (get-buffer-window (current-buffer)) 'reuse)) + + ((when-let ((right-window (window-in-direction 'right)) + ((eq joe/popper-side-toggle 'right))) + (window--display-buffer + buffer right-window 'reuse + `((body-function . ,#'select-window))))) + ((and (not (window-in-direction 'right)) (not (window-in-direction 'left))) (display-buffer-in-direction @@ -898,6 +912,8 @@ The theme of `C-x 4` bindings is that they operate on other windows, so this fun (add-hook 'project-find-functions #'joe/project-root-override) +(global-set-key (kbd "") #'set-frame-name) + #+end_src ** VEMCO @@ -1238,7 +1254,7 @@ startup. Reason we have to call this is so the vterm fucntion can call `vterm--i (straight-use-package 'undo-fu) (straight-use-package 'undo-fu-session) (straight-use-package 'vundo) -(global-undo-fu-session-mode) +(undo-fu-session-global-mode +1) (setq undo-fu-session-incompatible-files '("/COMMIT_EDITMSG\\'" "/git-rebase-todo\\'")) @@ -1453,7 +1469,30 @@ println!("Hello world"); *** Compilation #+begin_src emacs-lisp (setq compilation-auto-jump-to-first-error t) -(define-key global-map (kbd "") #'recompile) + +(defun joe/save-then-recompile () + "Save the buffer before recompiling" + (interactive) + (when (buffer-file-name) + (save-buffer)) + (recompile)) + +(defun joe/save-if-file-ignore-args (&rest _) + "Save the buffer before recompiling" + (interactive) + (joe/save-if-file)) + +(defun joe/save-if-file () + "Save buffer only if it has a backing file" + (interactive) + (when (buffer-file-name) + (save-buffer))) + +(define-key global-map (kbd "M-s") #'save-buffer) +(add-hook 'evil-insert-state-exit-hook #'joe/save-if-file) +(add-hook 'after-change-functions #'joe/save-if-file-ignore-args) +;; (define-key global-map (kbd "C-x C-s) #'save-buffer) +(define-key global-map (kbd "") #'joe/save-then-recompile) (define-key global-map (kbd "") #'compile) #+end_src ** Debugging @@ -1494,37 +1533,6 @@ println!("Hello world"); (define-key inferior-python-mode-map (kbd "C-n") #'comint-next-input) (define-key inferior-python-mode-map (kbd "C-p") #'comint-previous-input) #+end_src> -*** C - -Design some basic functions for compiling. There's also a hook to close the popper window if there -are no warnings or errors. It will check if we are still in the compilation buffer as well as -whether the point hasn't been moved. This way, if I switched to another popper buffer, like vterm, -it doesn't close it. - -#+begin_src emacs-lisp -(straight-use-package 'disaster) -(defun joe/c-mode-hook () - (local-set-key (kbd "C-x c r") (defun joe/make-run () (interactive) (compile "make run"))) - (local-set-key (kbd "C-x c c") (defun joe/make () (interactive) (compile "make"))) - (electric-pair-local-mode t) - (c-toggle-comment-style -1)) -(add-hook 'c-mode-hook #'joe/c-mode-hook) - -(defun joe/close-compilation-if-no-warn-err (buffer string) - "Bury a compilation buffer if succeeded without warnings " - (if (and - (string-match "compilation" (buffer-name buffer)) - (string-match "finished" string) - (not - (with-current-buffer (current-buffer) - (search-forward "warning" nil t)))) - (run-with-timer 1.5 nil - (lambda () - (and (eq (point) 1) - (string-match "compilation" (buffer-name (current-buffer))) - (popper-close-latest)))))) -(add-hook 'compilation-finish-functions 'joe/close-compilation-if-no-warn-err) -#+end_src *** Rust #+begin_src emacs-lisp (straight-use-package 'rustic) @@ -1562,6 +1570,37 @@ it doesn't close it. #+begin_src emacs-lisp (global-set-key (kbd "C-x C-r") 'eval-region) #+end_src +*** C + +Design some basic functions for compiling. There's also a hook to close the popper window if there +are no warnings or errors. It will check if we are still in the compilation buffer as well as +whether the point hasn't been moved. This way, if I switched to another popper buffer, like vterm, +it doesn't close it. + +#+begin_src emacs-lisp +(straight-use-package 'disaster) +(defun joe/c-mode-hook () + (local-set-key (kbd "C-x c r") (defun joe/make-run () (interactive) (compile "make run"))) + (local-set-key (kbd "C-x c c") (defun joe/make () (interactive) (compile "make"))) + (electric-pair-local-mode t) + (c-toggle-comment-style -1)) +(add-hook 'c-mode-hook #'joe/c-mode-hook) + +(defun joe/close-compilation-if-no-warn-err (buffer string) + "Bury a compilation buffer if succeeded without warnings " + (if (and + (string-match "compilation" (buffer-name buffer)) + (string-match "finished" string) + (not + (with-current-buffer (current-buffer) + (search-forward "warning" nil t)))) + (run-with-timer 1.5 nil + (lambda () + (and (eq (point) 1) + (string-match "compilation" (buffer-name (current-buffer))) + (popper-close-latest)))))) +(add-hook 'compilation-finish-functions 'joe/close-compilation-if-no-warn-err) +#+end_src *** Haskell #+begin_src emacs-lisp (straight-use-package 'haskell-mode) @@ -1569,6 +1608,12 @@ it doesn't close it. (evil-define-key 'insert haskell-interactive-mode-map (kbd "C-n") #'haskell-interactive-mode-history-next) (evil-define-key 'insert haskell-interactive-mode-map (kbd "C-p") #'haskell-interactive-mode-history-previous) +#+end_src +*** Clojure +#+begin_src emacs-lisp +(straight-use-package 'clojure-mode) +(straight-use-package 'cider) +(setq cider-show-error-buffer 'only-in-repl) #+end_src *** OCaml #+begin_src emacs-lisp @@ -1615,12 +1660,6 @@ and there's no need for a middle-man when it's already been implemented. ;; Use opam switch to lookup ocamlmerlin binary (setq merlin-command 'opam))) #+end_src -*** Clojure -#+begin_src emacs-lisp -(straight-use-package 'clojure-mode) -(straight-use-package 'cider) -(setq cider-show-error-buffer 'only-in-repl) -#+end_src *** FSharp #+begin_src emacs-lisp (straight-use-package 'fsharp-mode) diff --git a/.config/fish/functions/e.fish b/.config/fish/functions/e.fish index b27559b..4ba3ab6 100644 --- a/.config/fish/functions/e.fish +++ b/.config/fish/functions/e.fish @@ -1,3 +1,3 @@ -function e --wraps=nvim --description 'alias e nvim' +function e --wraps=emacsclient -n $argv emacsclient -n $argv; end