New theme, close comp buffer, dirvish, precision scrolling, olivetti integration

This commit is contained in:
Joseph Ferano 2022-08-28 17:45:33 +07:00
parent 863a121609
commit 8d928c9ccb

View File

@ -202,6 +202,7 @@ Simple functions to remember the last chosen theme.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(straight-use-package 'doom-themes) (straight-use-package 'doom-themes)
(straight-use-package 'color-theme-sanityinc-tomorrow)
(setq custom-safe-themes t) (setq custom-safe-themes t)
(defun joe/save-current-theme () (defun joe/save-current-theme ()
@ -232,7 +233,7 @@ Setup other stuff
(make-variable-buffer-local 'global-hl-line-mode) (make-variable-buffer-local 'global-hl-line-mode)
(dolist (mode '( dashboard-mode-hook org-mode-hook term-mode-hook eww-mode-hook vterm-mode-hook (dolist (mode '( dashboard-mode-hook org-mode-hook term-mode-hook eww-mode-hook vterm-mode-hook
eshell-mode-hook dired-mode-hook shell-mode-hook magit-mode-hook)) eshell-mode-hook dired-mode-hook shell-mode-hook magit-mode-hook compilation-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 0)))) (add-hook mode (lambda () (display-line-numbers-mode 0))))
(set-window-margins nil 0) (set-window-margins nil 0)
@ -248,6 +249,9 @@ Setup other stuff
'((right-divider-width . 5) '((right-divider-width . 5)
(internal-border-width . 12))) (internal-border-width . 12)))
(when (>= emacs-major-version 29)
(pixel-scroll-precision-mode t))
(setq inhibit-startup-screen t) (setq inhibit-startup-screen t)
(straight-use-package 'ligature) (straight-use-package 'ligature)
@ -277,7 +281,16 @@ Setup other stuff
** Buffers ** Buffers
#+begin_src emacs-lisp #+begin_src emacs-lisp
(global-set-key (kbd "C-x k") #'kill-this-buffer) (defun joe/kill-this-buffer-or-popup ()
(interactive)
"Kill the buffer normally, but if it's a popper popup, call the popper version"
(with-current-buffer (current-buffer)
(if (or (eq popper-popup-status nil)
(eq popper-popup-status 'raised))
(kill-this-buffer)
(popper-kill-latest-popup))))
(global-set-key (kbd "C-x k") #'joe/kill-this-buffer-or-popup)
(global-set-key (kbd "C-x M-k") #'kill-buffer) (global-set-key (kbd "C-x M-k") #'kill-buffer)
(straight-use-package 'all-the-icons-ibuffer) (straight-use-package 'all-the-icons-ibuffer)
(add-hook 'ibuffer-mode-hook #'all-the-icons-ibuffer-mode) (add-hook 'ibuffer-mode-hook #'all-the-icons-ibuffer-mode)
@ -311,6 +324,9 @@ The theme of `C-x 4` bindings is that they operate on other windows, so this fun
#+end_src #+end_src
** Windows ** Windows
*** Popper
#+begin_src emacs-lisp #+begin_src emacs-lisp
(require 'winner) (require 'winner)
(winner-mode t) (winner-mode t)
@ -328,6 +344,8 @@ The theme of `C-x 4` bindings is that they operate on other windows, so this fun
(setq popper-reference-buffers (setq popper-reference-buffers
'("\\*compilation\\*" compilation-mode '("\\*compilation\\*" compilation-mode
"^\\*vterm\\*" vterm-mode "^\\*vterm\\*" vterm-mode
"^\\*Flymake.*" flymake-mode
;; "^\\*ansi-term\\*$" term-mode
("^\\*Warnings\\*$" . hide) ("^\\*Warnings\\*$" . hide)
help-mode help-mode
helpful-mode)) helpful-mode))
@ -339,23 +357,60 @@ The theme of `C-x 4` bindings is that they operate on other windows, so this fun
(popper-echo-mode t) (popper-echo-mode t)
(defun joe/get-popper-dir () (defun joe/get-popper-dir ()
(if (> (window-width) 170) (with-current-buffer (current-buffer)
joe/popper-side-toggle (if (or (> (window-width) 170) (eq olivetti-mode t))
'below)) joe/popper-side-toggle
'below)))
;; TODO Consider adding checks for vertical splits and only popup on right if so ;; TODO Consider adding checks for vertical splits and only popup on right if so
(defun joe/popper-display-func (buffer &optional _alist) (defun joe/popper-display-func (buffer &optional _alist)
(display-buffer-in-direction (display-buffer-in-direction
buffer buffer
`((window-height . 0.4) `((window-height . 0.4)
(window-width . 0.4) (window-width . 0.4)
(direction . ,(joe/get-popper-dir)) (direction . ,(joe/get-popper-dir))
(body-function . ,#'select-window)))) (body-function . ,#'select-window))))
(setq popper-display-function #'joe/popper-display-func) (setq popper-display-function #'joe/popper-display-func)
(popper-mode t) (popper-mode t)
#+end_src #+end_src
*** Scrolling
#+begin_src emacs-lisp
(require 'pixel-scroll)
(setq pixel-scroll-precision-large-scroll-height 10.0)
(setq pixel-scroll-precision-interpolation-factor 30)
(defun joe/smooth-scroll-half-page-down ()
"Smooth scroll down"
(interactive)
(let ((half-height (/ (window-height) 2)))
(pixel-scroll-precision-interpolate (* 5 (- half-height)))))
(defun joe/smooth-scroll-half-page-up ()
"Smooth scroll down"
(interactive)
(let ((half-height (/ (window-height) 2)))
(pixel-scroll-precision-interpolate (* 5 half-height))))
(defun joe/smooth-scroll-short-down ()
"Smooth scroll down"
(interactive)
(let ((half-height (/ (window-height) 6)))
(pixel-scroll-precision-interpolate (* 5 (- half-height)))))
(defun joe/smooth-scroll-short-up ()
"Smooth scroll down"
(interactive)
(let ((half-height (/ (window-height) 6)))
(pixel-scroll-precision-interpolate (* 5 half-height))))
;; scroll-up-command
(global-set-key (kbd "C-v") #'joe/smooth-scroll-half-page-down)
(global-set-key (kbd "M-v") #'joe/smooth-scroll-half-page-up)
#+end_src
** Org Mode ** Org Mode
#+begin_src emacs-lisp #+begin_src emacs-lisp
(straight-use-package 'org-bullets) (straight-use-package 'org-bullets)
@ -369,7 +424,7 @@ The theme of `C-x 4` bindings is that they operate on other windows, so this fun
(with-eval-after-load 'org (joe/org-init)) (with-eval-after-load 'org (joe/org-init))
(defun joe/org-hook () (defun joe/org-hook ()
(local-set-key (kbd "C-. C-i") 'consult-outline) (local-set-key (kbd "C-. C-i") 'consult-org-heading)
(org-bullets-mode) (org-bullets-mode)
(org-indent-mode)) (org-indent-mode))
(add-hook 'org-mode-hook 'joe/org-hook) (add-hook 'org-mode-hook 'joe/org-hook)
@ -483,16 +538,25 @@ Vertico Embark Marginalia Consult Orderless
"Use `exa' to generate directory preview." "Use `exa' to generate directory preview."
:require ("exa") ; tell Dirvish to check if we have the executable :require ("exa") ; tell Dirvish to check if we have the executable
(when (file-directory-p file) ; we only interest in directories here (when (file-directory-p file) ; we only interest in directories here
`(shell . ("exa" "-H" "--icons" "--color=always" "--no-user" "-al" "--group-directories-first" ,file)))) `(shell . ("exa" "--icons" "--color=always" "--no-user" "-al" "--group-directories-first" ,file))))
(add-to-list 'dirvish-preview-dispatchers 'exa) (add-to-list 'dirvish-preview-dispatchers 'exa)
(setq dired-listing-switches "-l --almost-all --human-readable --time-style=long-iso --group-directories-first --no-group") (setq dired-listing-switches "-l --sort=version --almost-all --human-readable --time-style=long-iso --group-directories-first --no-group")
(setq dirvish-preview-dispatchers (cl-substitute 'pdf-preface 'pdf dirvish-preview-dispatchers)) (setq dirvish-preview-dispatchers (cl-substitute 'pdf-preface 'pdf dirvish-preview-dispatchers))
(setq dirvish-attributes '(all-the-icons file-size collapse subtree-state)) (setq dirvish-attributes '(all-the-icons file-size collapse subtree-state))
(defun joe/dirvish-find-directory (dir) (defun joe/dirvish-find-directory (dir)
(interactive "FDirvish Directory:") (interactive "FDirvish Directory:")
(dirvish-dwim dir)) (dirvish-dwim dir))
(straight-use-package 'magit)
(require 'magit)
(setq dirvish-quick-access-entries
'(("h" "~/" "Home")
("d" "~/Downloads/" "Downloads")
("D" "~/Documents/" "Documents")
("b" "~/Documents/Books/" "Books")
("p" "~/Development/" "Dev")
("B" "~/pCloudDrive/" "pCloud")))
(global-set-key (kbd "C-x d") #'dirvish-dwim) (global-set-key (kbd "C-x d") #'dirvish-dwim)
(global-set-key (kbd "C-x C-d") #'joe/dirvish-find-directory) (global-set-key (kbd "C-x C-d") #'joe/dirvish-find-directory)
@ -502,7 +566,7 @@ Vertico Embark Marginalia Consult Orderless
(define-key dirvish-mode-map (kbd "f" ) #'dirvish-file-info-menu) (define-key dirvish-mode-map (kbd "f" ) #'dirvish-file-info-menu)
(define-key dirvish-mode-map (kbd "y" ) #'dirvish-yank-menu) (define-key dirvish-mode-map (kbd "y" ) #'dirvish-yank-menu)
(define-key dirvish-mode-map (kbd "N" ) #'dirvish-narrow) (define-key dirvish-mode-map (kbd "N" ) #'dirvish-narrow)
(define-key dirvish-mode-map (kbd "^" ) #'dirvish-history-last) (define-key dirvish-mode-map (kbd "^" ) #'dired-up-directory)
(define-key dirvish-mode-map (kbd "h" ) #'dirvish-history-jump) (define-key dirvish-mode-map (kbd "h" ) #'dirvish-history-jump)
(define-key dirvish-mode-map (kbd "s" ) #'dirvish-quicksort) (define-key dirvish-mode-map (kbd "s" ) #'dirvish-quicksort)
(define-key dirvish-mode-map (kbd "v" ) #'dirvish-vc-menu) (define-key dirvish-mode-map (kbd "v" ) #'dirvish-vc-menu)
@ -567,21 +631,37 @@ Vertico Embark Marginalia Consult Orderless
Emacs is an great operating system, if only it had a good text editor... Emacs is an great operating system, if only it had a good text editor...
*** Text editing
#+begin_src emacs-lisp
(global-set-key (kbd "M-z") #'zap-up-to-char)
(global-set-key (kbd "M-Z") #'zap-to-char)
;; (setq explicit-shell-file-name "~/Development/fell/fell")
(defun joe/duplicate-line-comment ()
(interactive)
(let ((col (current-column)))
(duplicate-line)
(comment-line 1)
(move-to-column col)))
(global-set-key (kbd "C-c d") 'duplicate-line)
(global-set-key (kbd "C-c C-;") 'joe/duplicate-line-comment)
#+end_src
*** Hydra *** Hydra
#+begin_src emacs-lisp #+begin_src emacs-lisp
(require 'view)
(straight-use-package 'hydra) (straight-use-package 'hydra)
(require 'hydra) (require 'hydra)
(defhydra hydra-zoom (global-map "<f2>") (defhydra hydra-navigate (global-map "<f2>")
"Window Manipulation" "Window Navigation"
("g" text-scale-increase "in") ("d" joe/smooth-scroll-half-page-down "half page down")
("l" text-scale-decrease "out") ("u" joe/smooth-scroll-half-page-up "half page up")
("d" View-scroll-half-page-forward "half page down") ("e" joe/smooth-scroll-short-down "line down")
("u" View-scroll-half-page-backward "half page up") ("y" joe/smooth-scroll-short-up "line up")
("e" View-scroll-line-forward "line down") ("n" next-line "line down")
("y" View-scroll-line-backward "line up") ("p" previous-line "line up")
) ("M-r" move-to-window-line-top-bottom "Reposition cursor"))
#+end_src #+end_src
*** Multiple Cursors *** Multiple Cursors
@ -729,12 +809,15 @@ Emacs is an great operating system, if only it had a good text editor...
#+end_src #+end_src
** IDE Features ** IDE Features
*** C *** LSP/Company
#+begin_src emacs-lisp #+begin_src emacs-lisp
;; (straight-use-package 'yasnippet) ;; (straight-use-package 'yasnippet)
(straight-use-package 'markdown-mode) (straight-use-package 'markdown-mode)
(straight-use-package 'lsp-mode) (straight-use-package 'lsp-mode)
(setq lsp-keymap-prefix "C-c l")
;; (straight-use-package 'eglot) ;; (straight-use-package 'eglot)
;; (setq completion-in-region-function (kind-icon-enhance-completion completion-in-region-function)) ;; (setq completion-in-region-function (kind-icon-enhance-completion completion-in-region-function))
@ -763,11 +846,11 @@ Emacs is an great operating system, if only it had a good text editor...
(with-eval-after-load 'company (with-eval-after-load 'company
(define-key company-active-map (kbd "C-n") nil) (define-key company-active-map (kbd "C-n") nil)
(define-key company-active-map (kbd "C-p") nil) (define-key company-active-map (kbd "C-p") nil)
(define-key company-active-map (kbd "RET") nil) (define-key company-active-map (kbd "<return>") nil)
(define-key company-active-map (kbd "C-f") #'company-complete-selection) (define-key company-active-map (kbd "C-f") #'company-complete-selection)
(define-key company-active-map [tab] #'company-complete-common-or-cycle) (define-key company-active-map [tab] #'company-complete-common-or-cycle)
(define-key company-active-map (kbd "<backtab>") (lambda () (interactive) (company-complete-common-or-cycle -1)))) (define-key company-active-map (kbd "<backtab>") (lambda () (interactive) (company-complete-common-or-cycle -1))))
(global-company-mode) (add-hook 'after-init-hook (lambda () (global-company-mode)))
;; (delete 'elisp-completion-at-point completion-at-point-functions) ;; (delete 'elisp-completion-at-point completion-at-point-functions)
;; (delete 'cape-symbol completion-at-point-functions) ;; (delete 'cape-symbol completion-at-point-functions)
@ -808,10 +891,33 @@ Emacs is an great operating system, if only it had a good text editor...
;; (yas-global-mode 1) ;; (yas-global-mode 1)
#+end_src #+end_src
*** Compilation *** 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 #+begin_src emacs-lisp
(global-set-key (kbd "C-x c r") (lambda () (interactive) (compile "make run"))) (defun joe/c-mode-hook ()
(global-set-key (kbd "C-x c c") (lambda () (interactive) (compile "make"))) (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"))))
(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 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 #+end_src
** Magit ** Magit