Skip to content

Commit

Permalink
browse recent symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
JJPandari committed Oct 17, 2023
1 parent 74e49ac commit 2372b74
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ site-lisp/package/
/games
/eaf
/straight/
/tree-sitter
1 change: 1 addition & 0 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
(require 'init-compile)
(require 'init-formatter)

(require 'init-tree-sitter)
(require 'init-paredit)

(require 'init-lisp)
Expand Down
3 changes: 2 additions & 1 deletion modes/init-editing-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
(global-page-break-lines-mode))


(use-package string-inflection)
(use-package string-inflection
:demand t)


(use-package subword
Expand Down
4 changes: 2 additions & 2 deletions modes/init-evil.el
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,9 @@
:states '(normal visual operator motion)
"0" 'jester/cycle-line-beginning-end)

;; TODO try citre-read or clue

;; TODO show bookmark name in fringe

;; TODO in jsx, "' s" if no useState register yet, auto create one


(provide 'init-evil)
6 changes: 5 additions & 1 deletion modes/init-face.el
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@
;;----------------------------------------------------------------------------
(defvar jester-small-font-size
(pcase window-system
('ns 150)
('mac 150)
('w32 140)
('x 140)
('nil 140))
"small font size depending on system.")
(defvar jester-large-font-size
(pcase window-system
('ns 160)
('mac 160)
('w32 150)
('x 150)
Expand All @@ -66,6 +68,7 @@
;; :family "JetBrains Mono"
;; :family "Fira Code"
:height jester-small-font-size
;; :weight 'regular
:weight 'medium
:width 'normal)
(jester/set-fallback-fonts))
Expand All @@ -78,6 +81,7 @@
;; :family "JetBrains Mono"
;; :family "Fira Code"
:height jester-large-font-size
;; :weight 'regular
:weight 'medium
:width 'normal)
(jester/set-fallback-fonts))
Expand All @@ -93,7 +97,7 @@

(jester/use-large-font)
;; try out ligatures
(when *is-a-mac* (mac-auto-operator-composition-mode 1))
(when (and *is-a-mac* (boundp 'mac-auto-operator-composition-mode)) (mac-auto-operator-composition-mode 1))

;;----------------------------------------------------------------------------
;; show trailing whitespace
Expand Down
4 changes: 2 additions & 2 deletions modes/init-git.el
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"g l" 'magit-log
"g f" 'magit-find-file
;; "a" ≈ "actions"
"g a" 'magit-dispatch-popup)
:commands (magit-status magit-diff-buffer-file magit-dispatch-popup)
"g a" 'magit-dispatch)
:commands (magit-status magit-diff-buffer-file magit-dispatch)
:config
;; quit rev selection in a rebase or something
(jester/with-major-leader
Expand Down
16 changes: 15 additions & 1 deletion modes/init-gui-frames.el
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,26 @@
`((fullscreen . ,(cond
;; ((eq window-system 'x) 'fullboth)
((eq window-system 'x) 'maximized) ;; wsl favours maximized
((eq window-system 'mac) 'fullboth)
;; ((eq window-system 'mac) 'fullboth)
((eq window-system 'ns) 'maximized)
((eq window-system 'mac) 'maximized)
(t 'maximized)))
;; left & top are required on wsl to correctly position
(left . (+ 0))
(top . (+ 0))
(undecorated . t)))


;; (use-package holo-layer
;; :ensure nil
;; :straight (holo-layer :type git :host github :repo "manateelazycat/holo-layer"
;; :files ("*" (:exclude ".git" "test")))
;; :init
;; (setq holo-layer-enable-cursor-animation t)
;; :demand t
;; :if window-system
;; :config
;; (holo-layer-enable))


(provide 'init-gui-frames)
97 changes: 44 additions & 53 deletions modes/init-ivy.el
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,6 @@
"H-S-s" (lambda! (swiper (jester/region-or-symbol)))
"C-s" 'swiper-isearch)

(defun jester/maybe-run-ivy-hydra ()
"Run `hydra-ivy/body' if there is any content in minibuffer."
(unless (save-excursion (beginning-of-line) (looking-at "$"))
(hydra-ivy/body)))

(defmacro jester/make-fuzzy-search-dwim-command (search-cmd)
"Make a fuzzy search dwim command with the search command `search-cmd'."
;; TODO ...
())

(defun jester/swiper-dwim ()
"If region is not active, just start swiper. If region contain 1 char, grab the symbol as swiper input, otherwise use the region content.
If swiper started with any input, enable ivy-hydra automatically. (so I can h/j/k/l the list)"
(interactive)
(if (region-active-p)
(minibuffer-with-setup-hook 'jester/maybe-run-ivy-hydra
(swiper (regexp-quote (let* ((beg (region-beginning))
(end (region-end))
(text (progn (deactivate-mark)
(buffer-substring-no-properties
beg end))))
(if (= (- end beg) 1)
(thing-at-point 'symbol t)
text)))))
(swiper)))

(general-define-key
:states '(normal motion)
"/" 'jester/swiper-dwim)

(defun jester/self-insert-or-search-previous ()
"Search previous if nothing in the input area, otherwise self insert."
(interactive)
(if (save-excursion (beginning-of-line) (looking-at "$"))
(progn (call-interactively 'previous-complete-history-element)
(end-of-line))
(call-interactively 'self-insert-command)))
(general-define-key
:keymaps 'swiper-map
"/" 'jester/self-insert-or-search-previous
Expand Down Expand Up @@ -149,22 +112,6 @@ If swiper started with any input, enable ivy-hydra automatically. (so I can h/j/
"/" 'jester/self-insert-or-search-previous
"M-/" (lambda! (insert "/")))

(defun jester/counsel-rg-dwim ()
"If region is not active, just start counsel-rg. If region contain 1 char, grab the symbol as counsel-rg input, otherwise use the region content.
If counsel-rg started with any input, enable ivy-hydra automatically. (so I can h/j/k/l the list)"
(interactive)
(if (region-active-p)
(minibuffer-with-setup-hook 'jester/maybe-run-ivy-hydra
(counsel-rg (regexp-quote (let* ((beg (region-beginning))
(end (region-end))
(text (progn (deactivate-mark)
(buffer-substring-no-properties
beg end))))
(if (= (- end beg) 1)
(thing-at-point 'symbol t)
text)))))
(counsel-rg)))

(defun jester/fzf-somewhere (&optional start-dir)
"Do `counsel-fzf' in directory START-DIR.
If called interactively, let the user select start directory first."
Expand Down Expand Up @@ -281,6 +228,50 @@ If called interactively, let the user select start directory first."
;; :config
;; (company-prescient-mode 1))

;;----------------------------------------------------------------------------
;; search buffer/project, with easy-to-use key bindings
;;----------------------------------------------------------------------------
(defun jester/maybe-run-ivy-hydra ()
"Run `hydra-ivy/body' if there is any content in minibuffer."
(unless (save-excursion (beginning-of-line) (looking-at "$"))
(hydra-ivy/body)))

(defmacro jester/make-fuzzy-search-dwim-command (search-cmd)
"Make a dwim fuzzy search command, using `search-cmd'."
`(defun ,(intern (format "jester/%s-dwim" search-cmd)) ()
,(format "If region is not active, just start %s. If region contain 1 char, grab the symbol as %s input, otherwise use the region content.
If %s started with any input, enable ivy-hydra automatically. (so I can h/j/k/l the list)"
search-cmd search-cmd search-cmd)
(interactive)
(if (region-active-p)
(minibuffer-with-setup-hook 'jester/maybe-run-ivy-hydra
(,search-cmd (regexp-quote (let* ((beg (region-beginning))
(end (region-end))
(text (progn (deactivate-mark)
(buffer-substring-no-properties
beg end))))
(if (= (- end beg) 1)
(thing-at-point 'symbol t)
text)))))
(,search-cmd))))

(jester/make-fuzzy-search-dwim-command swiper) ; jester/swiper-dwim

(general-define-key
:states '(normal motion)
"/" 'jester/swiper-dwim)

(jester/make-fuzzy-search-dwim-command counsel-rg) ; jester/counsel-rg-dwim

(defun jester/self-insert-or-search-previous ()
"Search previous if nothing in the input area, otherwise self insert."
(interactive)
(if (save-excursion (beginning-of-line) (looking-at "$"))
(progn (call-interactively 'previous-complete-history-element)
(end-of-line))
(call-interactively 'self-insert-command)))


;;----------------------------------------------------------------------------
;; Pre-fill search keywords
;; https://with-emacs.com/posts/execute-commands-like-marty-mcfly/
Expand Down
5 changes: 4 additions & 1 deletion modes/init-javascript.el
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
;; (setq flycheck-checker 'javascript-eslint))
:mode "\\.ts\\'"
:config

(setq auto-mode-alist (cl-remove "\\.tsx?\\'" auto-mode-alist :test 'string-equal :key 'car))

;; (require 'ansi-color)
;; (defun colorize-compilation-buffer ()
;; (ansi-color-apply-on-region compilation-filter-start (point-max)))
Expand Down Expand Up @@ -192,7 +195,7 @@
".test.jsx" ".spec.jsx"
".test.ts" ".spec.ts"
".test.tsx" ".spec.tsx")))
(setq jester-test-command (format "(cd %s && node node_modules/.bin/jest --detectOpenHandles --forceExit %s --collectCoverageOnlyFrom '')" (projectile-project-root) file-name)))))
(setq jester-test-command (format "(cd %s && node node_modules/.bin/jest --detectOpenHandles --forceExit %s --collectCoverageFrom '')" (projectile-project-root) file-name)))))

(add-hook! '(js2-mode-hook typescript-mode-hook web-mode-hook) 'jester/set-js-ts-test-command)

Expand Down
62 changes: 57 additions & 5 deletions modes/init-jump.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
;; )
;; TODO use the macro for "/"
(jester/with-leader
"b l" 'counsel-evil-marks
"b n" 'bookmark-set
"b j" 'bookmark-jump)

Expand Down Expand Up @@ -38,10 +39,6 @@
"e n" 'lsp-bridge-diagnostic-jump-next
"e p" 'lsp-bridge-diagnostic-jump-prev)


;; TODO xref-ring
;; (advice-add 'xref-find-definitions :after )


(use-package dumb-jump
:init
Expand All @@ -68,7 +65,62 @@
;; (citre-tags-file-names '("tagz" ".tags" "tags")))
;; :init
;; (require 'citre-config))
;; TODO try `citre-peek'

;;----------------------------------------------------------------------------
;; save recent find-def(find-ref ?) targets in a ring, one ring for each project,
;; so they can be looked up with ivy
;;----------------------------------------------------------------------------
(ignore-errors (make-directory (locate-user-emacs-file "var/jester")))
(setq jester-project-symbol-history-file (locate-user-emacs-file "var/jester/project-symbol-history.el"))

(defun jester/read-symbol-history ()
"Read symbol history from `jester-project-symbol-history-file'."
(setq jester-project-symbols-map
(if (file-exists-p jester-project-symbol-history-file)
(with-temp-buffer
(insert-file-contents jester-project-symbol-history-file)
(read (current-buffer)))
(ht-create))))

(jester/read-symbol-history)

(defun jester/write-symbol-history ()
"Save `jester-project-symbols-map.'"
(let ((filename jester-project-symbol-history-file))
(with-temp-buffer
(insert ";;; -*- lisp-data -*-\n")
(let ((print-length nil)
(print-level nil))
(pp jester-project-symbols-map (current-buffer)))
(write-region nil nil filename nil 'silent))))

(defun jester/save-symbol-history (&optional sym-arg)
"Advice for find def, save current symbol to history."
(let* ((project-root (projectile-project-root))
(sym (if sym-arg sym-arg (thing-at-point 'symbol t)))
(sym-map-in-project (or (ht-get jester-project-symbols-map project-root)
(ht-create))))
;; clear text properties
(set-text-properties 0 (length sym) nil sym)
(ht-set! sym-map-in-project sym (list (buffer-file-name) (point)))
(ht-set! jester-project-symbols-map project-root sym-map-in-project)
(jester/write-symbol-history)))

(advice-add 'xref-find-definitions :before 'jester/save-symbol-history)
(advice-add 'lsp-bridge-find-def :before 'jester/save-symbol-history)

(defun jester/recent-symbol ()
"Select a recent symbol, goto it (place before find-def)."
(interactive)
(let ((sym-map-in-project (ht-get jester-project-symbols-map (projectile-project-root))))
(ivy-read "recent symbol: "
(ht-map (lambda (sym _) sym)
sym-map-in-project)
:action (lambda (selected-sym) (let ((place-info (ht-get sym-map-in-project selected-sym)))
(find-file (car place-info))
(goto-char (nth 1 place-info)))))))

(jester/with-leader "s l" 'jester/recent-symbol)


(provide 'init-jump)
3 changes: 0 additions & 3 deletions modes/init-lsp-bridge.el
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

(evil-set-initial-state 'lsp-bridge-ref-mode 'emacs)

;; TODO what's the face for error pop?
(set-face-attribute 'lsp-bridge-ref-font-lock-diagnostic nil :foreground (face-attribute 'error :foreground))

(jester/with-minor-leader 'lsp-bridge-mode
"d" 'lsp-bridge-popup-documentation)

Expand Down
3 changes: 2 additions & 1 deletion modes/init-misc.el
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
:config
(after-load 'recentf
(add-to-list 'recentf-exclude no-littering-var-directory)
(add-to-list 'recentf-exclude no-littering-etc-directory)))
(add-to-list 'recentf-exclude no-littering-etc-directory))
(setq yas-snippet-dirs (list (expand-file-name "snippets" user-emacs-directory))))


;; (use-package emacs-gc-stats
Expand Down
4 changes: 2 additions & 2 deletions modes/init-shell.el
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
"C-c" 'vterm--self-insert
"C-," (lambda! (vterm--backward-char))
"C-." (lambda! (vterm--forward-char))
"<C-i>" 'vterm-beginning-of-line
"C-o" 'vterm-end-of-line
"<C-i>" 'vterm-send-C-a
"C-o" 'vterm-send-C-e
"S-<backspace>" 'vterm-send-delete
"H-w" (lambda! (vterm-send "C-w"))
"H-v" 'vterm-yank
Expand Down
10 changes: 10 additions & 0 deletions modes/init-tree-sitter.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(setq treesit-language-source-alist '((javascript . ("https://github.com/tree-sitter/tree-sitter-javascript"))
(typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src"))
(tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src"))
(python . ("https://github.com/tree-sitter/tree-sitter-python"))
(rust . ("https://github.com/tree-sitter/tree-sitter-rust"))))

;; M-x treesit-install-language-grammar


(provide 'init-tree-sitter)
3 changes: 3 additions & 0 deletions modes/init-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
(use-package dash
:demand t)

(use-package ht
:demand t)

(use-package move-text
:demand t)

Expand Down
Loading

0 comments on commit 2372b74

Please sign in to comment.