Skip to content

Commit

Permalink
revisit load theme hook
Browse files Browse the repository at this point in the history
  • Loading branch information
JJPandari committed Jun 20, 2023
1 parent 009d343 commit a9003d2
Show file tree
Hide file tree
Showing 24 changed files with 280 additions and 231 deletions.
3 changes: 2 additions & 1 deletion init.el
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@
(require 'init-frame-hooks)
(require 'init-themes)
(require 'init-gui-frames)
(require 'init-face)
;; (require 'init-eaf)

(require 'init-osx-keys)
(require 'init-evil)
;; (require 'init-meow)
(require 'init-which-key)
(require 'init-hydra)
(require 'init-multi-cursors)

(require 'init-editing-utils)

Expand All @@ -75,7 +77,6 @@
(require 'init-windows)
(require 'init-mode-line)
(require 'init-sessions)
(require 'init-face)
(require 'init-avy)
(require 'init-help)
(require 'init-read)
Expand Down
10 changes: 6 additions & 4 deletions modes/init-avy.el
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
(use-package avy
:init
(setq avy-all-windows t)
;; (jester/with-leader "j j" 'avy-goto-char-timer)
:commands (avy-goto-char-timer))
;; (general-define-key
;; :states '(normal visual motion)
;; "g a" 'avy-goto-char-timer)
(jester/with-leader "a" 'evil-avy-goto-char-timer))

(use-package link-hint
:after avy
:commands link-hint-open-link
:init
(jester/with-leader
"l o" 'link-hint-open-link))
"l o" 'link-hint-open-link
"l <return>" 'link-hint-open-link-at-point))

(provide 'init-avy)
36 changes: 33 additions & 3 deletions modes/init-editing-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
(use-package undo-fu
:init
(general-define-key
:states '(emacs)
"C-/" 'undo-fu-only-undo
"C-?" 'undo-fu-only-redo)
:demand t
Expand Down Expand Up @@ -128,6 +127,36 @@
:config
(add-hook 'prog-mode-hook 'eldoc-box-hover-mode))

;;----------------------------------------------------------------------------
;; highlight region with symbol-overlay
;;----------------------------------------------------------------------------
(use-package symbol-overlay
:hook ((prog-mode . symbol-overlay-mode)
(css-mode . symbol-overlay-mode)
(yaml-mode . symbol-overlay-mode)
(conf-mode . symbol-overlay-mode)
(markdown-mode . symbol-overlay-mode)
(help-mode . symbol-overlay-mode))
:init
;; don't put temporary highlight
(setq symbol-overlay-idle-time 0)
:config
(general-define-key
:states '(normal visual motion)
:keymaps '(prog-mode-map css-mode yaml-mode conf-mode markdown-mode help-mode)
"<tab>" 'symbol-overlay-put
"H-n" 'symbol-overlay-jump-next
"H-p" 'symbol-overlay-jump-prev)
(jester/with-leader "o p" 'symbol-overlay-put)
;; don't bind any key
(setq symbol-overlay-map (make-sparse-keymap)))

;;----------------------------------------------------------------------------
;; face related key bindings
;;----------------------------------------------------------------------------
(jester/with-leader
"t c" 'text-scale-adjust)

;;----------------------------------------------------------------------------
;; smart ; key
;;----------------------------------------------------------------------------
Expand Down Expand Up @@ -204,8 +233,9 @@
(insert-or-remove-trailing-char ?,))

(general-define-key
"H-;" 'insert-or-remove-trailing-semi
"H-," 'insert-or-remove-trailing-comma)
"C-;" 'insert-or-remove-trailing-semi
"C-:" 'insert-or-remove-trailing-comma)
;; TODO merge these two, use treesit to know which to do

;;----------------------------------------------------------------------------
;; Move lines up and down.
Expand Down
146 changes: 16 additions & 130 deletions modes/init-evil.el
Original file line number Diff line number Diff line change
Expand Up @@ -203,129 +203,6 @@
"g C" 'evil-snipe-X)
(define-key evil-normal-state-map (kbd "DEL") 'evil-snipe-repeat-reverse))


;; TODO fix paste
(use-package evil-multiedit
:demand t
;; :commands (evil-multiedit-match-all evil-multiedit-match-symbol-and-next evil-multiedit-match-symbol-and-prev)
:init
(setq evil-multiedit-use-symbols t)
;; Ex command that allows you to invoke evil-multiedit with a regular expression, e.g.
(evil-ex-define-cmd "ie[dit]" 'evil-multiedit-ex-match)
(general-define-key
:states '(normal visual)
"R" 'jester/evil-multiedit-match-all
"C-n" 'evil-multiedit-match-and-next
"C-p" 'evil-multiedit-match-and-prev)
(defun jester/evil-multiedit-match-all ()
"Match all occurences. with prefix arg, exclude those in comments or strings."
(interactive)
(evil-multiedit-match-all)
(when current-prefix-arg
(save-excursion
(let ((pos))
(iedit-goto-first-occurrence)
(setq pos (point))
(unless (jester/in-expression-area-p)
(evil-multiedit-toggle-or-restrict-region))
(while (evil-multiedit-next)
(unless (jester/in-expression-area-p)
(evil-multiedit-toggle-or-restrict-region)))))))
:config
(general-define-key
:states '(normal)
:keymaps 'evil-multiedit-mode-map
"<return>" 'evil-multiedit-toggle-or-restrict-region
"<tab>" 'evil-multiedit-next
"<S-tab>" 'evil-multiedit-prev
"C-n" 'evil-multiedit-match-and-next
"C-p" 'evil-multiedit-match-and-prev)
(general-define-key
:states '(insert emacs)
:keymaps 'evil-multiedit-mode-map
"<tab>" 'jester/start-complete
"C-a" 'evil-multiedit-beginning-of-line
"C-e" 'evil-multiedit-end-of-line)
)


(use-package evil-mc
:init
;; don't bind any keys
(setq evil-mc-key-map (make-sparse-keymap))
;; (general-define-key
;; :states '(normal visual)
;; "K" 'evil-mc-make-all-cursors
;; "M-n" 'evil-mc-make-and-goto-next-match
;; "M-p" 'evil-mc-make-and-goto-prev-match
;; "M-j" 'evil-mc-make-cursor-move-next-line
;; "M-k" 'evil-mc-make-cursor-move-prev-line
;; "<M-return>" 'jester/evil-mc-toggle-cursors-pause)
(defun jester/evil-mc-toggle-cursors-pause ()
"Toggle between pausing or resuming all cursors."
(interactive)
(if evil-mc-frozen
(evil-mc-resume-cursors)
(evil-mc-pause-cursors)))
:commands (evil-mc-make-all-cursors evil-mc-make-cursor-here
evil-mc-make-cursor-move-next-line evil-mc-make-cursor-move-prev-line
evil-mc-make-and-goto-next-match evil-mc-make-and-goto-prev-match)
:config
(advice-add 'evil-force-normal-state :after 'evil-mc-undo-all-cursors)
;; FIXME activate mode after using some command may be buggy, but it's the only way to lazy-load evil-mc now.
(global-evil-mc-mode 1)

;; Add custom commands to whitelisted commands
;; TODO not work
(dolist (fn '(string-inflection-kebab-case
string-inflection-camelcase string-inflection-lower-camelcase
jester/expand-yas-or-complete-company))
(push (cons fn '((:default . evil-mc-execute-default-call)))
evil-mc-custom-known-commands)))


;; https://github.com/abo-abo/hydra/wiki/multiple-cursors
(use-package multiple-cursors
:init
(general-define-key
:states '(emacs)
"M-j" 'mc/mark-next-like-this
"M-k" 'mc/mark-previous-like-this
"M-n" 'mc/mark-next-like-this-symbol
"M-p" 'mc/mark-previous-like-this-symbol)
;; TODO not work
(general-define-key
:states '(emacs)
:keymaps 'mc/keymap
"<escape>" 'mc/keyboard-quit)
(general-define-key :keymaps 'mc/keymap "<return>" nil)

(defhydra hydra-multiple-cursors (:hint nil :exit nil)
"
Up^^ Down^^ Miscellaneous % 2(mc/num-cursors) cursor%s(if (> (mc/num-cursors) 1) \"s\" \"\")
------------------------------------------------------------------
[_p_] Next [_n_] Next [_l_] Edit lines [_0_] Insert numbers
[_P_] Skip [_N_] Skip [_a_] Mark all [_A_] Insert letters
[_M-p_] Unmark [_M-n_] Unmark [_s_] Search [_q_] Quit
[_|_] Align with input CHAR [Click] Cursor at point"
("l" mc/edit-lines :exit t)
("a" mc/mark-all-like-this :exit t)
("n" mc/mark-next-like-this)
("N" mc/skip-to-next-like-this)
("M-n" mc/unmark-next-like-this)
("p" mc/mark-previous-like-this)
("P" mc/skip-to-previous-like-this)
("M-p" mc/unmark-previous-like-this)
("|" mc/vertical-align)
("s" mc/mark-all-in-region-regexp :exit t)
("0" mc/insert-numbers :exit t)
("A" mc/insert-letters :exit t)
("<mouse-1>" mc/add-cursor-on-click)
;; Help with click recognition in this hydra
("<down-mouse-1>" ignore)
("<drag-mouse-1>" ignore)
("q" nil)))


(use-package evil-collection
:demand t
Expand All @@ -339,11 +216,14 @@
(evil-collection-init)

;; modify a bit after evil-collection setup
;; TODO not overridding evil-collection?
(general-define-key
:states '(normal)
:keymaps '(magit-mode-map magit-diff-mode-map magit-log-mode-map)
"/" 'jester/swiper-dwim))

;; evil-collection sets up keys in `after-load-functions', so setting keys directly won't work
;; not sure why but after-load fixes this
(after-load 'magit
(general-define-key
:states '(normal)
:keymaps '(magit-mode-map magit-diff-mode-map magit-log-mode-map)
"/" 'jester/swiper-dwim)))


(use-package evil-numbers
Expand Down Expand Up @@ -488,6 +368,7 @@
;;----------------------------------------------------------------------------
(jester/with-leader
"f i" (lambda! (find-file (expand-file-name "init.el" user-emacs-directory)))
"f o" (lambda! (find-file "~/org/todo.org"))
"f a" 'find-alternate-file
"h f" 'describe-function
"h F" 'list-faces-display
Expand Down Expand Up @@ -535,6 +416,8 @@
"Q" "@q"
"gJ" 'jester/evil-join-no-whitespace
"z i" 'evil-emacs-state
"<C-i>" 'beginning-of-line-text
"C-o" 'move-end-of-line
"<" nil
">" nil)

Expand Down Expand Up @@ -565,6 +448,7 @@
"Q" ":norm @q <return>"

;; fix keys bound by motion state
"r" 'evil-replace
"d" 'evil-delete)

(general-define-key
Expand Down Expand Up @@ -657,7 +541,8 @@
"H-x" 'kill-region
"H-c" 'kill-ring-save
"H-v" 'yank
;; reserve C-r for commands similar to backward-search
"H-g" 'keyboard-quit
;; reserve C-r / H-r for commands similar to backward-search
;; "C-y" 'evil-paste-from-register
"M-." 'forward-word
"M-," 'backward-word
Expand Down Expand Up @@ -759,8 +644,9 @@
(dolist (cmd '(evil-yank evil-delete lispyville-yank lispyville-delete))
(advice-add cmd :after 'jester/evil-portal-jump-advice))

(defun jester/cycle-line-beginning-end ()
(evil-define-command jester/cycle-line-beginning-end ()
"Go to line text beginning, line end, line very beginning, in turn."
:repeat nil
(interactive)
(cl-block 'my-return
(when (and (looking-at "[^\s]") (looking-back "^\s*")) (evil-end-of-line) (cl-return-from 'my-return)) ; at beg of line text
Expand Down
42 changes: 8 additions & 34 deletions modes/init-face.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@

(use-package highlight-parentheses
:demand t
:init
(customize-set-variable 'highlight-parentheses-colors
'("springgreen3" "IndianRed1" "IndianRed3" "IndianRed4"
"#2aa198" "#b58900" "#268bd2" "#6c71c4" "#859900"))
:config
(global-highlight-parentheses-mode 1)
;; run after init due to `reapply-themes'
;; TODO load-theme-hook
(add-hook! :append 'after-init-hook
(add-hook! 'load-theme-hook
;; the theme's setting will take precedence if simply `setq'
(customize-set-variable 'hl-paren-colors '("Springgreen3" "firebrick1" "IndianRed1" "IndianRed3" "IndianRed4")))
(customize-set-variable 'highlight-parentheses-colors
'("springgreen3" "IndianRed1" "IndianRed3" "IndianRed4"
"#2aa198" "#b58900" "#268bd2" "#6c71c4" "#859900")))
(set-face-attribute 'hl-paren-face nil :weight 'bold))
(use-package rainbow-delimiters
:hook (prog-mode . rainbow-delimiters-mode))
Expand All @@ -36,30 +40,6 @@
;; (use-package nerd-icons
;; :demand t)

;;----------------------------------------------------------------------------
;; highlight region with symbol-overlay
;;----------------------------------------------------------------------------
(use-package symbol-overlay
:hook ((prog-mode . symbol-overlay-mode)
(css-mode . symbol-overlay-mode)
(yaml-mode . symbol-overlay-mode)
(conf-mode . symbol-overlay-mode)
(markdown-mode . symbol-overlay-mode)
(help-mode . symbol-overlay-mode))
:init
;; don't put temporary highlight
(setq symbol-overlay-idle-time 0)
:config
(general-define-key
:states '(normal visual motion)
:keymaps '(prog-mode-map css-mode yaml-mode conf-mode markdown-mode help-mode)
"<tab>" 'symbol-overlay-put
"H-n" 'symbol-overlay-jump-next
"H-p" 'symbol-overlay-jump-prev)
(jester/with-leader "o p" 'symbol-overlay-put)
;; don't bind any key
(setq symbol-overlay-map (make-sparse-keymap)))

;;----------------------------------------------------------------------------
;; Set fonts.
;;----------------------------------------------------------------------------
Expand Down Expand Up @@ -137,11 +117,5 @@ This is helpful for writeroom-mode, in particular."
(add-hook 'visual-fill-column-mode-hook
'jester/maybe-adjust-visual-fill-column)

;;----------------------------------------------------------------------------
;; face related key bindings
;;----------------------------------------------------------------------------
(jester/with-leader
"t c" 'text-scale-adjust)


(provide 'init-face)
1 change: 1 addition & 0 deletions modes/init-file.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
;; yas overlay and company-select-next has problem with this.
(when (and (not yas--active-snippets)
;; (not company-candidates)
(not acm-mode)
(not (eq major-mode 'snippet-mode)))
;; https://github.com/manateelazycat/lazycat-emacs/commit/da13a688ef89f8ab2c577a3e9d2a7bcf0ef9b71d
;; https://emacs-china.org/t/topic/7687/30?u=jjpandari
Expand Down
4 changes: 2 additions & 2 deletions modes/init-git.el
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"g t" 'git-timemachine)
:commands git-timemachine
:config
(add-hook! 'git-timemachine-mode-hook (evil-motion-state 1))
(evil-set-initial-state 'git-timemachine-mode 'motion)
(general-define-key
:states 'motion
:keymaps 'git-timemachine-mode-map
Expand Down Expand Up @@ -54,7 +54,7 @@
magit-bury-buffer-function 'magit-restore-window-configuration
magit-log-margin '(t "周%u %Y-%m-%d %H:%M:%S %z" magit-log-margin-width t 18))
(jester/with-leader
"g s" 'magit-status
"g j" 'magit-status
"g d" 'magit-diff-buffer-file
"g r" 'diff-hl-revert-hunk
"g l" 'magit-log
Expand Down
Loading

0 comments on commit a9003d2

Please sign in to comment.