Skip to content

Commit

Permalink
better company-number, use citre(ctags) for big codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
JJPandari committed Nov 8, 2021
1 parent 28a84ed commit 1e365eb
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 71 deletions.
1 change: 1 addition & 0 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
(require 'init-face)
(require 'init-avy)
(require 'init-help)
(require 'init-read)

(require 'init-flycheck)
(require 'init-vc)
Expand Down
7 changes: 4 additions & 3 deletions modes/init-company.el
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@

(defun ora-company-number ()
"Forward to `company-complete-number'.
Unless the number is potentially part of the candidate.
In that case, insert the number."
In these cases just insert the number:
1. the number is potentially part of the candidate
2. last character is a number "
(interactive)
(let* ((k (this-command-keys))
(re (concat "^" company-prefix k)))
(if (or (cl-find-if (lambda (s) (string-match re s))
company-candidates)
(> (string-to-number k)
(length company-candidates))
(looking-back "[0-9]+\\.[0-9]*" (line-beginning-position)))
(looking-back "[0-9]"))
(self-insert-command 1)
(company-complete-number
(if (equal k "0")
Expand Down
4 changes: 3 additions & 1 deletion modes/init-editing-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,9 @@ If use-indirect-buffer is not nil, use `indirect-buffer' to hold the widen conte
;;----------------------------------------------------------------------------
(defvar jester-flip-symbol-alist
'(("true" . "false")
("false" . "true"))
("false" . "true")
("GET" . "POST")
("POST" . "GET"))
"symbols to be quick flipped when editing")

(defun jester/just-do-what-i-mean ()
Expand Down
31 changes: 22 additions & 9 deletions modes/init-evil.el
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@
;; NOTE: "a" "d" "." "'" are still there for the taking
"," 'evil-indent
"!" 'shell-command
"'" 'evil-use-register)
"<" 'evil-shift-left
">" 'evil-shift-right)

;;----------------------------------------------------------------------------
;; With-major-leader keys...
Expand All @@ -457,7 +458,9 @@
(general-define-key
:states '(normal)
"Q" "@q"
"gJ" 'jester/evil-join-no-whitespace)
"gJ" 'jester/evil-join-no-whitespace
"<" nil
">" nil)

(general-define-key
:states '(normal)
Expand All @@ -482,8 +485,6 @@
:states '(visual)
"*" 'jester/evil-visual-search-forward
"#" 'jester/evil-visual-search-backward
"<" (lambda! (call-interactively 'evil-shift-left) (execute-kbd-macro "gv"))
">" (lambda! (call-interactively 'evil-shift-right) (execute-kbd-macro "gv"))
;; run macro in the q register on all selected lines
"Q" ":norm @q <return>"

Expand Down Expand Up @@ -516,8 +517,9 @@

(general-define-key
:states '(insert emacs)
"C-b" 'delete-char
;; "C-o" 'evil-open-below
"M-v" 'evil-scroll-down
"M-c" 'evil-scroll-up
"C-b" 'delete-forward-char
"C-d" 'backward-char
"C-n" 'next-line
"C-p" 'previous-line
Expand All @@ -528,8 +530,6 @@
"C-v" 'yank
"M-d" 'backward-word
"M-b" 'kill-word
"M-v" 'evil-scroll-down
"M-c" 'evil-scroll-up
"H-x" 'kill-region)

;;----------------------------------------------------------------------------
Expand All @@ -539,7 +539,20 @@
"C-h C-f" 'list-faces-display
"C-h p" 'describe-package
"C-h c" 'describe-char
"C-h K" 'find-function-on-key)
"C-h K" 'find-function-on-key
;; copy insert state bindings here, so keys do the same when evil disabled
"C-b" 'delete-forward-char
"C-d" 'backward-char
"C-n" 'next-line
"C-p" 'previous-line
"C-a" 'beginning-of-line-text
"C-e" 'move-end-of-line
"C-k" 'kill-line
"C-w" 'evil-delete-backward-word
"C-v" 'yank
"M-d" 'backward-word
"M-b" 'kill-word
"H-x" 'kill-region)

;;----------------------------------------------------------------------------
;; Some functions.
Expand Down
1 change: 1 addition & 0 deletions modes/init-help.el
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"L" 'Info-next
"C-r" 'Info-history
"f" 'link-hint-open-link
"<return>" 'Info-follow-nearest-node
"g g" 'evil-goto-first-line)


Expand Down
58 changes: 18 additions & 40 deletions modes/init-javascript.el
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,6 @@
(use-package js-doc
:after js2-mode)


(use-package xref-js2
:custom (xref-js2-search-program 'rg)
:init
(add-hook 'js2-mode-hook
(lambda () (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t)))
(defun jester/js2-jump-or-xref-definition ()
"`js2-jump-to-definition' if we can, `xref-find-definitions' if can't or already at import statement."
(interactive)
(if (save-excursion
(beginning-of-line)
(let ((case-fold-search nil)) (search-forward "import " nil t)))
(xref-find-definitions (xref-backend-identifier-at-point (xref-find-backend)))
(condition-case err
(js2-jump-to-definition)
(error (xref-find-definitions (xref-backend-identifier-at-point (xref-find-backend)))))))
(general-define-key
:states '(normal motion)
:keymaps '(js2-mode-map)
"g d" 'jester/js2-jump-or-xref-definition
"g r" 'jester/xref-find-references-at-point))


(use-package skewer-mode
:init
Expand Down Expand Up @@ -171,24 +149,6 @@
(interactive)
(message (kill-new (format "http://localhost:%s/%s" jester-monkey-scripts-port (buffer-name)))))


(defun jester/prettier-js-file-1 ()
"Call prettier on current file."
(interactive)
(call-process-shell-command (format "node %s --write %s"
(f-join (projectile-project-root) "node_modules/.bin/prettier")
(buffer-file-name))))

(defun jester/prettier-js-file-2 ()
"Call prettier on current file."
(interactive)
(save-restriction
(widen)
(call-process-region (point-min) (point-max) "prettier" t t t)))

;; (jester/with-major-leader '(js2-mode-map web-mode-map typescript-mode-map)
;; "p" 'jester/prettier-js-file-1)


(defun jester/make-default-evil-markers-for-js ()
"Make some evil markers to my habit."
Expand Down Expand Up @@ -235,5 +195,23 @@

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


(defun jester/js2-jump-or-citre-jump ()
"`js2-jump-to-definition' if we can, `citre-jump' if can't or already at import statement."
(interactive)
(if (save-excursion
(beginning-of-line)
(let ((case-fold-search nil)) (search-forward "import " nil t)))
(citre-jump)
(condition-case err
(js2-jump-to-definition)
(error (citre-jump)))))
(general-define-key
:states '(normal motion)
:keymaps '(js2-mode-map)
"g d" 'jester/js2-jump-or-citre-jump
;; "g r" 'jester/xref-find-references-at-point
)


(provide 'init-javascript)
36 changes: 23 additions & 13 deletions modes/init-jump.el
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,30 @@
;;----------------------------------------------------------------------------
;; xref
;;----------------------------------------------------------------------------
(defun jester/xref-find-references-at-point ()
"Find references for symbol at point."
(interactive)
(xref-find-references (xref-backend-identifier-at-point (xref-find-backend))))

(general-define-key
:states '(normal motion)
"g d" 'xref-find-definitions
"g p" 'xref-pop-marker-stack)
(general-define-key
:definer 'minor-mode
:states 'normal
:keymaps 'lsp-mode
"g r" 'jester/xref-find-references-at-point)


(use-package dumb-jump
:init
(setq dumb-jump-aggressive t
dumb-jump-selector 'ivy)
;; sets the global value, will be overwritten by major mode / lsp
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate))


(use-package ivy-xref
:init
;; xref initialization is different in Emacs 27 - there are two different
Expand All @@ -26,19 +43,12 @@
;; as well
(setq xref-show-xrefs-function #'ivy-xref-show-xrefs))

(defun jester/xref-find-references-at-point ()
"Find references for symbol at point."
(interactive)
(xref-find-references (xref-backend-identifier-at-point (xref-find-backend))))

(use-package citre
:custom (citre-tags-files '("tagz" ".tags" "tags"))
:init
(require 'citre-config))
;; TODO try `citre-peek'

(general-define-key
:states '(normal motion)
"g d" 'xref-find-definitions
"g p" 'xref-pop-marker-stack)
(general-define-key
:definer 'minor-mode
:states 'normal
:keymaps 'lsp-mode
"g r" 'jester/xref-find-references-at-point)

(provide 'init-jump)
8 changes: 7 additions & 1 deletion modes/init-lisp.el
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@
(when-let* ((doc (and (fboundp sym) (documentation sym 'raw)))
(stripped-advice-doc (replace-regexp-in-string
;; regex from ivy-rich
":\\(\\(before\\|after\\)\\(-\\(while\\|until\\)\\)?\\|around\\|override\\|\\(filter-\\(args\\|return\\)\\)\\) advice:[ ]*‘.+?’[\r\n]+"
(rx bos
(1+ (seq (? "This function has ")
(or ":before" ":after" ":around" ":override"
":before-while" ":before-until" ":after-while"
":after-until" ":filter-args" ":filter-return")
" advice: " (0+ nonl) "\n"))
"\n")
""
doc))
(oneline (substring stripped-advice-doc 0 (string-match "\n" stripped-advice-doc))))
Expand Down
1 change: 1 addition & 0 deletions modes/init-lsp.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(lsp-prefer-flymake nil)
(lsp-restart 'auto-restart)
(lsp-enable-symbol-highlighting nil)
(lsp-enable-indentation nil)
;; don't mess with my `company-backends'
(lsp-completion-enable nil)
(lsp-headerline-breadcrumb-enable nil)
Expand Down
8 changes: 7 additions & 1 deletion modes/init-mode-line.el
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@
" %1"
jester/flycheck-mode-line

"%1"
;; current project folder name
'(:eval (when-let ((full-dir (locate-dominating-file "." ".git/")))
(propertize (concat " " (file-name-as-directory (file-name-nondirectory (directory-file-name full-dir))))
'face 'dired-directory)))

"%1"
;; git info
'(:eval (when vc-mode
(s-replace "Git" (propertize "" 'face '(:family "github-octicons")) (propertize vc-mode))))
(s-replace "Git" (propertize "" 'face '(:family "github-octicons")) vc-mode)))

;; minor modes
;; minor-mode-alist
Expand Down
34 changes: 34 additions & 0 deletions modes/init-paredit.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
;; parens are taken care by paredit etc., others shall be electric.
(after-init (electric-pair-mode 1)) ;; this is global


(push (expand-file-name "awesome-pair" jester-submodules-dir) load-path)
(use-package awesome-pair
:ensure nil
Expand Down Expand Up @@ -50,4 +51,37 @@
"d" 'evil-delete
"c" 'evil-change))


(use-package puni
:init
;; (general-define-key
;; :states '(insert emacs)
;; :keymaps '(prog-mode-map)
;; ;; delete commands
;; [remap backward-delete-char] 'puni-backward-delete-char
;; [remap backward-delete-char-untabify] 'puni-backward-delete-char
;; [remap delete-char] 'puni-forward-delete-char
;; [remap delete-forward-char] 'puni-forward-delete-char
;; [remap kill-word] 'puni-forward-kill-word
;; [remap backward-kill-word] 'puni-backward-kill-word
;; [remap evil-delete-backward-word] 'puni-backward-kill-word
;; [remap kill-line] 'puni-kill-line
;; [remap jester/kill-back-to-indentation] 'puni-backward-kill-line
;; ;; (define-key map (kbd "C-c DEL") 'puni-force-delete)
;; [remap kill-region] 'puni-kill-active-region
;; ;; navigation commands
;; [remap forward-sexp] 'puni-forward-sexp
;; [remap backward-sexp] 'puni-backward-sexp
;; [remap beginning-of-sexp] 'puni-beginning-of-sexp
;; [remap end-of-sexp] 'puni-end-of-sexp)
(general-define-key
:states '(normal)
:keymaps 'prog-mode-map
;; manipulating commands
"<" 'puni-slurp-forward
">" 'puni-barf-forward
"M->" 'puni-slurp-backward
"M-<" 'puni-barf-backward))


(provide 'init-paredit)
2 changes: 2 additions & 0 deletions modes/init-php.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
;; (evil-define-key 'insert php-mode-map (kbd "C-l") (lambda () (interactive) (insert "->")))
;; (evil-define-key 'insert php-mode-map (kbd "C-j") (lambda () (interactive) (insert " => ")))

;; phps-mode


(provide 'init-php)
5 changes: 2 additions & 3 deletions modes/init-web.el
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
web-mode-style-padding 0
web-mode-script-padding 0
web-mode-block-padding 0
web-mode-enable-current-element-highlight t
web-mode-enable-current-element-highlight nil
web-mode-enable-auto-indentation nil
web-mode-comment-formats '(("java" . "//") ("javascript" . "//") ("typescript" . "//") ("php" . "//") ("css" . "/*")))
(setq-default
Expand Down Expand Up @@ -59,9 +59,8 @@
(when (string-equal (file-name-extension (buffer-name)) "tsx")
(lsp)
;; lsp sets checker to lsp, set it back
;; lsp and eslint show different errors, using lsp for now...
;; `flycheck-add-next-checker'
;; (setq flycheck-checker 'javascript-eslint)
(setq flycheck-checker 'javascript-eslint)
(jester/make-default-evil-markers-for-js)
(setq emmet-expand-jsx-className? t)))

Expand Down

0 comments on commit 1e365eb

Please sign in to comment.