Skip to content

Commit

Permalink
lsp and jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
JJPandari committed Oct 28, 2019
1 parent 610f486 commit c650bc5
Show file tree
Hide file tree
Showing 35 changed files with 434 additions and 193 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ site-lisp/package/
/forge-database.sqlite
/server
/transient
/.lsp-*
7 changes: 4 additions & 3 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,19 @@

(require 'init-vc)
(require 'init-git)
(require 'init-compile)

(require 'init-paredit)

(require 'init-lisp)
;; (require 'init-scheme)
(require 'init-scheme)
;; (require 'init-slime)
;; (require 'init-clojure)
;; (require 'init-clojure-cider)
;; (require 'init-common-lisp)
(require 'init-paredit)

(require 'init-lsp)
(require 'init-jump)
;; (require 'init-compile)
(require 'init-text)
(require 'init-org)
(require 'init-markdown)
Expand Down
24 changes: 2 additions & 22 deletions modes/init-company.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"C-p" #'company-select-previous
"<C-m>" 'company-complete-common
"<tab>" 'expand-snippet-or-complete-selection
"C-b" 'company-show-doc-buffer
"C-g" 'company-abort
"<escape>" (lambda! (company-abort) (evil-normal-state)))
(dotimes (i 10)
Expand Down Expand Up @@ -75,10 +74,6 @@
(backward-char 1)
(if (looking-at "->") t nil)))))

(defun do-yas-expand ()
(let ((yas-fallback-behavior 'return-nil))
(yas-expand)))

(defun tab-indent-or-complete ()
(interactive)
(cond
Expand All @@ -87,7 +82,7 @@
(t
;; (indent-for-tab-command)
(if (and (or (not yas-minor-mode)
(null (do-yas-expand)))
(null (yas-expand)))
(check-expansion))
(progn
(company-manual-begin)
Expand All @@ -99,25 +94,10 @@
)))
))))

;; (defun tab-complete-or-next-field ()
;; (interactive)
;; (if (or (not yas-minor-mode)
;; (null (do-yas-expand)))
;; (if company-candidates
;; (company-complete-selection)
;; (if (check-expansion)
;; (progn
;; (company-manual-begin)
;; (if (null company-candidates)
;; (progn
;; (company-abort)
;; (yas-next-field))))
;; (yas-next-field)))))

(defun expand-snippet-or-complete-selection ()
(interactive)
(if (or (not yas-minor-mode)
(null (do-yas-expand))
(null (yas-expand))
(company-abort))
(company-complete-selection)))

Expand Down
66 changes: 31 additions & 35 deletions modes/init-compile.el
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
(setq-default compilation-scroll-output t)
(setq compilation-read-command nil
compilation-scroll-output t)


(require-package 'alert)

;; Customize `alert-default-style' to get messages after compilation
(setq alert-default-style (pcase window-system
('x 'x11)
('mac 'osx-notifier)
(_ 'message)))

(defun jester/alert-after-compilation-finish (buf result)
"Use `alert' to report compilation RESULT if BUF is hidden."
Expand All @@ -20,45 +24,37 @@
(add-hook 'compilation-finish-functions
'jester/alert-after-compilation-finish))

(defvar jester/last-compilation-buffer nil
"The last buffer in which compilation took place.")

(after-load 'compile
(defadvice compilation-start (after jester/save-compilation-buffer activate)
"Save the compilation buffer to find it later."
(setq jester/last-compilation-buffer next-error-last-buffer))

(defadvice recompile (around jester/find-prev-compilation (&optional edit-command) activate)
"Find the previous compilation buffer, if present, and recompile there."
(if (and (null edit-command)
(not (derived-mode-p 'compilation-mode))
jester/last-compilation-buffer
(buffer-live-p (get-buffer jester/last-compilation-buffer)))
(with-current-buffer jester/last-compilation-buffer
ad-do-it)
ad-do-it)))

(global-set-key [f6] 'recompile)

(defadvice shell-command-on-region
(after jester/shell-command-in-view-mode
(start end command &optional output-buffer replace &rest other-args)
activate)
"Put \"*Shell Command Output*\" buffers into view-mode."
(unless (or output-buffer replace)
(with-current-buffer "*Shell Command Output*"
(view-mode 1))))



(after-load 'compile
(require 'ansi-color)
(defun jester/colourise-compilation-buffer ()
(when (eq major-mode 'compilation-mode)
(ansi-color-apply-on-region compilation-filter-start (point-max))))
(add-hook 'compilation-filter-hook 'jester/colourise-compilation-buffer))


(maybe-require-package 'cmd-to-echo)

(defvar-local jester-run-command nil
"shell command to run the project.")

(defun jester/run-project ()
"Run it with `compile' and `jester-run-command'."
(interactive)
(if jester-run-command
(compile jester-run-command)
(user-error "no run command configured for %s" major-mode))
;; switch to "*compilation*" buffer because it's configured not to show when `compile'
(switch-to-buffer "*compilation*"))

(jester/with-leader
;; TODO assign a key to "cargo check"?
"c i" 'compile ;; "compile it!"
"c l" (lambda! (switch-to-buffer "*compilation*"))
"c r" 'jester/run-project)

(general-define-key
:states '(motion)
:keymaps 'compilation-mode-map
"f" 'link-hint-open-link)


(provide 'init-compile)
1 change: 1 addition & 0 deletions modes/init-dired.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
;; NOTE: remap doesn't change when dired-* is called from code
(jester/with-leader
"f d" 'dired-jump)
:custom (ranger-show-hidden 'format)
:bind (([remap dired-jump] . deer)
:map ranger-mode-map
("s" . 'ranger-sort-criteria))
Expand Down
115 changes: 73 additions & 42 deletions modes/init-editing-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
:hook ((js2-mode . electric-operator-mode)
(css-mode . electric-operator-mode)
(sass-mode . electric-operator-mode)
(rust-mode . electric-operator-mode)
;; (rust-mode . electric-operator-mode)
(java-mode . electric-operator-mode)
(python-mode . electric-operator-mode)
(sql-mode . electric-operator-mode)
Expand Down Expand Up @@ -225,21 +225,34 @@ Effectively using symbol before point as the key."
"<C-i>" 'jester/make-key-value-pair)

;;----------------------------------------------------------------------------
;; Make a "foo: bar;" key-value pair
;; Insert " = " for me, please.
;;----------------------------------------------------------------------------
(defun jester/make-css-pair ()
"Make a key-value pair for css etc., by inserting \": ;\" at point."
(interactive)
(insert ": ;") (backward-char))
(defmacro jester/def-make-assignment-function (fun-name eol-str &rest forms-for-bolt)
"Define a function with the name of `FUN-NAME'.
`FORMS-FOR-BOLT' is some forms evaluated when point is at beginning of line text,
who decides which type of assignment we currently have, and change it to the next one.
Use `eol-str' as the tail."
`(defun ,fun-name ()
"Make a mode specific assignment statement,
using things left of point as left value, things right as right value.
(general-define-key
:states '(insert emacs)
:keymaps 'prog-mode-map
"M-;" 'jester/make-css-pair)
If nothing is at left, move point to the left value's position,
otherwise move to before semicolon.
If this line is already an assignment (has a \"=\"), cycle through some styles."
(interactive)
(save-match-data
(let ((need-signs (save-excursion
(beginning-of-line-text) (not (looking-at ".* = .*$"))))
(something-left-p (not (looking-back "^\s*"))))
(save-excursion
(if need-signs
(progn (insert " = ") (move-end-of-line 1)
(unless (looking-back ,eol-str) (insert ,eol-str)))
(beginning-of-line-text)
,@forms-for-bolt))
(when (and need-signs something-left-p) (move-end-of-line 1) (left-char))))))

;;----------------------------------------------------------------------------
;; Insert " = " for me, please.
;;----------------------------------------------------------------------------
(defvar jester-javascript-assignment-declarer
'var
"What word to use when making a javascript assignment.
Expand All @@ -258,26 +271,24 @@ If this line is already an assignment (has a \"=\"), cycle through styles in thi
a \"const\" assignment,
a \"let\" assignment."
(interactive)
(let ((need-signs (save-excursion (beginning-of-line-text) (not (looking-at ".* = .*$"))))
(something-left-p (not (looking-back "^\s*"))))
(save-excursion
(if need-signs
(progn (insert " = ") (move-end-of-line 1)
(unless (looking-back ";") (insert ";")))
(beginning-of-line-text)
(cond
((eq jester-javascript-assignment-declarer 'let)
(cond
((looking-at "const ") (kill-word 1) (insert "let"))
((looking-at "let ") (kill-word 1) (delete-char 1))
(t (insert "const "))))
((eq jester-javascript-assignment-declarer 'var)
(cond
((looking-at "var ") (kill-word 1) (delete-char 1))
(t (insert "var "))))
(t (user-error "Plz set `jester-javascript-assignment-declarer' to `let' or `var'")))
))
(when (and need-signs something-left-p) (move-end-of-line 1) (left-char))))
(save-match-data
(let ((need-signs (save-excursion (beginning-of-line-text) (not (looking-at ".* = .*$"))))
(something-left-p (not (looking-back "^\s*"))))
(save-excursion
(if need-signs
(progn (insert " = ") (move-end-of-line 1)
(unless (looking-back ";") (insert ";")))
(beginning-of-line-text)
(pcase jester-javascript-assignment-declarer
('let (cond
((looking-at "const ") (replace-match "let "))
((looking-at "let ") (replace-match ""))
(t (insert "const "))))
('var (cond
((looking-at "var ") (replace-match ""))
(t (insert "var "))))
(_ (user-error "Plz set `jester-javascript-assignment-declarer' to `let' or `var'")))))
(when (and need-signs something-left-p) (move-end-of-line 1) (left-char)))))

(general-define-key
:states '(insert emacs)
Expand All @@ -288,14 +299,16 @@ If this line is already an assignment (has a \"=\"), cycle through styles in thi
"Make a assignment statement,
using things left of point as left value, things right as right value.
Additional formats are added to this line as declared in `jester-assignment-format-alist'.
If nothing is at left, move point to the left value's position,
otherwise move to before semicolon."
(interactive)
(let ((need-signs (save-excursion (beginning-of-line-text) (not (looking-at ".* = .*$"))))
(something-left-p (not (looking-back "^\s*"))))
(save-excursion
(when need-signs
(progn (insert " = "))))
(progn (insert " = "))))
(when (and need-signs something-left-p) (move-end-of-line 1))))

(general-define-key
Expand Down Expand Up @@ -480,27 +493,45 @@ If use-indirect-buffer is not nil, use `indirect-buffer' to hold the widen conte
"Select an argument, without the punctuations."
:extend-selection nil
(list (progn
(re-search-backward "[,(] ?")
(re-search-backward (rx (sequence (or ","
"("
"["
"{")
(optional " "))))
(forward-char)
(when (eq (char-after (point)) ? ) (forward-char))
(point))
(progn (re-search-forward "[,] ?\\| ?)")
(while (memq (char-before) (list ?, ? ?\))) (backward-char))
(progn (re-search-forward (rx (or (sequence ","
(optional " "))
(sequence (optional " ")
(or ")"
"]"
"}")))))
(while (memq (char-before) (list ?, ? ?\) ?\] ?})) (backward-char))
(point))))

(evil-define-text-object jester/evil-a-arg (count &optional beg end type)
"Select an argument."
:extend-selection nil
(let* (last-arg-p
(head (progn
(re-search-backward "[,(] ?")
(re-search-backward (rx (sequence (or ","
"("
"["
"{")
(optional " "))))
(forward-char)
(when (eq (char-after (point)) ? ) (forward-char))
(point)))
(tail (progn (re-search-forward "[,] ?\\| ?)")
(setq last-arg-p (eq (char-before) ?\)))
(when (eq (char-before) ?\))
(while (memq (char-before) (list ? ?\))) (backward-char)))
(tail (progn (re-search-forward (rx (or (sequence ","
(optional " "))
(sequence (optional " ")
(or ")"
"]"
"}")))))
(setq last-arg-p (memq (char-before) (list ?\) ?\] ?})))
(when (memq (char-before) (list ?\) ?\] ?}))
(while (memq (char-before) (list ? ?\) ?\] ?})) (backward-char)))
(point))))
(when last-arg-p
(setq head (progn (goto-char head)
Expand Down
8 changes: 4 additions & 4 deletions modes/init-elpa.el
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
;; ("org-cn" . "https://elpa.emacs-china.org/org/")
;; ("gnu-cn" . "https://elpa.emacs-china.org/gnu/")
;; ("melpa-stable-cn" . "https://elpa.emacs-china.org/melpa-stable/")
("melpa-tuna" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")
("org-tuna" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/org/")
("gnu-tuna" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
("melpa-stable-tuna" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa-stable/")
("melpa-tuna" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")
("org-tuna" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/org/")
("gnu-tuna" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
("melpa-stable-tuna" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/melpa-stable/")
)
package-archives))

Expand Down
Loading

0 comments on commit c650bc5

Please sign in to comment.