Skip to content

Commit

Permalink
smart ; key
Browse files Browse the repository at this point in the history
  • Loading branch information
JJPandari committed Dec 30, 2019
1 parent c650bc5 commit 660ac9f
Show file tree
Hide file tree
Showing 48 changed files with 374 additions and 168 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ site-lisp/package/
/server
/transient
/.lsp-*
/.DS_Store
5 changes: 3 additions & 2 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
(require 'init-gui-frames)

(require 'init-osx-keys)
(require 'init-evil)
(require 'init-which-key)
(require 'init-hydra)
(require 'init-evil)

(require 'init-editing-utils)

Expand All @@ -58,7 +58,6 @@
(require 'init-file)
(require 'init-buffer)
(require 'init-minibuffer)
(require 'init-flycheck)

(require 'init-ivy)
;; (require 'init-helm)
Expand All @@ -69,7 +68,9 @@
(require 'init-sessions)
(require 'init-face)
(require 'init-avy)
(require 'init-help)

(require 'init-flycheck)
(require 'init-vc)
(require 'init-git)
(require 'init-compile)
Expand Down
6 changes: 1 addition & 5 deletions modes/init-avy.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
:commands link-hint-open-link
:init
(jester/with-leader
"l o" 'link-hint-open-link)
(general-define-key
:states '(motion)
:keymaps '(help-mode-map Man-mode-map)
"f" 'link-hint-open-link))
"l o" 'link-hint-open-link))

(provide 'init-avy)
1 change: 1 addition & 0 deletions modes/init-buffer.el
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ current window."
;;----------------------------------------------------------------------------
;; switch major mode
;;----------------------------------------------------------------------------
;; TODO standalone history with `ivy-read'
(defun jester/switch-mode ()
"Toggle some mode."
(interactive)
Expand Down
9 changes: 5 additions & 4 deletions modes/init-chinese.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
;; Enable Chinese word segmentation support (支持中文分词)
;; (setq youdao-dictionary-use-chinese-word-segmentation t)
(jester/with-leader "y y" 'youdao-dictionary-search-at-point+)
(jester/with-leader "y i" 'youdao-dictionary-search-from-input)
:bind ("C-c y" . youdao-dictionary-search-at-point+)
)
:hook (youdao-dictionary-mode . evil-motion-state))


(use-package pyim
:demand t
:config
(setq-default pyim-english-input-switch-functions
'(pyim-probe-dynamic-english
pyim-probe-isearch-mode
pyim-probe-program-mode
pyim-probe-org-structure-template)
;; pyim-probe-isearch-mode
;; pyim-probe-org-structure-template
)

pyim-punctuation-half-width-functions
'(pyim-probe-punctuation-line-beginning
Expand Down
19 changes: 10 additions & 9 deletions modes/init-company.el
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
company-dabbrev-ignore-case nil
company-dabbrev-downcase nil
company-minimum-prefix-length 2
company-idle-delay 0.1)
company-idle-delay 0.1
company-require-match nil)

;; clear default bindings first
(setq company-active-map (make-sparse-keymap))
Expand Down Expand Up @@ -67,12 +68,13 @@
;;----------------------------------------------------------------------------
;; https://emacs.stackexchange.com/a/7925/12854
(defun check-expansion ()
(save-excursion
(if (looking-at "\\_>") t
(backward-char 1)
(if (looking-at "\\.") t
(backward-char 1)
(if (looking-at "->") t nil)))))
;; (save-excursion
;; (if (looking-at "\\_>") t
;; (backward-char 1)
;; (if (looking-at "\\.") t
;; (backward-char 1)
;; (if (looking-at "->") t nil))))
t)

(defun tab-indent-or-complete ()
(interactive)
Expand All @@ -91,8 +93,7 @@
(company-abort)
(hippie-expand nil)
;; (indent-for-tab-command)
)))
))))
)))))))

(defun expand-snippet-or-complete-selection ()
(interactive)
Expand Down
42 changes: 29 additions & 13 deletions modes/init-compile.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
(setq compilation-read-command nil
compilation-scroll-output t)
(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)
(add-hook 'compilation-mode-hook 'jester/set-shell-buffer-face))


(require-package 'alert)
Expand All @@ -24,14 +31,6 @@
(add-hook 'compilation-finish-functions
'jester/alert-after-compilation-finish))


(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))


(defvar-local jester-run-command nil
"shell command to run the project.")
Expand All @@ -41,20 +40,37 @@
(interactive)
(if jester-run-command
(compile jester-run-command)
(user-error "no run command configured for %s" major-mode))
(user-error "no run command configured for this buffer, check mode hooks"))
;; switch to "*compilation*" buffer because it's configured not to show when `compile'
(switch-to-buffer "*compilation*"))


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

(defun jester/run-test ()
"Run it with `compile' and `jester-test-command'."
(interactive)
(if jester-test-command
(compile jester-test-command)
(user-error "no test command configured for this buffer, check mode hooks"))
;; 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)
"c i" 'compile ; "compile it!"
"c l" (lambda! (switch-to-buffer "*compilation*")) ; "compilation log"
"c r" 'jester/run-project
"c t" 'jester/run-test)

(general-define-key
:states '(motion)
:keymaps 'compilation-mode-map
"f" 'link-hint-open-link)
"h" 'evil-backward-char
"f" 'link-hint-open-link
"g g" 'evil-goto-first-line
"g r" 'recompile)


(provide 'init-compile)
7 changes: 4 additions & 3 deletions modes/init-dired.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
(when gls (setq insert-directory-program gls)))

(jester/with-major-leader 'ranger-mode-map
"w" 'wdired-change-to-wdired-mode)
"w" 'wdired-change-to-wdired-mode
"d" 'dired-create-directory)

(jester/with-major-leader 'wdired-mode-map
"," 'wdired-finish-edit
"a" 'wdired-abort-changes)
"," 'wdired-finish-edit
"a" 'wdired-abort-changes)

(use-package ranger
:init
Expand Down
64 changes: 45 additions & 19 deletions modes/init-editing-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@


(use-package electric-operator
:hook ((js2-mode . electric-operator-mode)
(css-mode . electric-operator-mode)
:hook (;; (js2-mode . electric-operator-mode)
;; (css-mode . electric-operator-mode)
(sass-mode . electric-operator-mode)
;; (rust-mode . electric-operator-mode)
(java-mode . electric-operator-mode)
Expand All @@ -99,6 +99,32 @@
(c-mode . electric-operator-mode)
(php-mode . electric-operator-mode)))

;;----------------------------------------------------------------------------
;; smart ; key
;;----------------------------------------------------------------------------
(defun jester/insert-\;or-: ()
"Insert a \";\" or \":\" according to context."
(interactive)jester-lispy-modes
(cond ((memq major-mode jester-lispy-modes) (insert ":"))
((derived-mode-p 'prog-mode) (if (eolp)
(insert ";")
(insert ":")))
(t (insert ";"))))

(defun jester/toggle-char-before-point-\;-or-: ()
"Toggle the char before point between \";\" or \":\"."
(interactive)
(pcase (char-before)
(?\; (delete-backward-char 1) (insert ":"))
(?\: (delete-backward-char 1) (insert ";"))
(_ (message "toggle \";\" or \":\": char before is neither \";\" nor \":\""))))

(general-define-key
:states '(insert emacs)
:keymaps 'prog-mode-map
";" 'jester/insert-\;or-:
":" 'jester/toggle-char-before-point-\;-or-:)

;;----------------------------------------------------------------------------
;; kill back to indentation
;;----------------------------------------------------------------------------
Expand Down Expand Up @@ -210,20 +236,6 @@
"H-t" 'jester/expand-to-ternary
"H-S-t" 'jester/expand-to-ternary-condensed)

;;----------------------------------------------------------------------------
;; Make a "foo: bar," key-value pair
;;----------------------------------------------------------------------------
(defun jester/make-key-value-pair ()
"Make a key-value pair, by inserting \": ,\" at point.
Effectively using symbol before point as the key."
(interactive)
(insert ": ,") (backward-char))

(general-define-key
:states '(insert emacs)
:keymaps 'prog-mode-map
"<C-i>" 'jester/make-key-value-pair)

;;----------------------------------------------------------------------------
;; Insert " = " for me, please.
;;----------------------------------------------------------------------------
Expand Down Expand Up @@ -254,7 +266,7 @@ If this line is already an assignment (has a \"=\"), cycle through some styles."
(when (and need-signs something-left-p) (move-end-of-line 1) (left-char))))))

(defvar jester-javascript-assignment-declarer
'var
'let
"What word to use when making a javascript assignment.
When set to `let', use \"let\" and \"const\".
When set to `var', use \"var\".")
Expand Down Expand Up @@ -334,8 +346,7 @@ otherwise move to before semicolon."
;;----------------------------------------------------------------------------
;; https://stackoverflow.com/a/22114743/4788022
(defun jester/insert-curly-and-go-inside ()
"Insert {}.
Threat is as function body when from endline before )"
"Insert {} on separate lines, and a new line in between."
(interactive)
(unless (looking-back "[ ({\\[]") (insert " "))
(insert "{\n\n}") (indent-according-to-mode)
Expand All @@ -346,6 +357,21 @@ Threat is as function body when from endline before )"
:keymaps '(prog-mode-map conf-mode-map)
"<C-return>" 'jester/insert-curly-and-go-inside)

;;----------------------------------------------------------------------------
;; insert a line below point
;;----------------------------------------------------------------------------
(defun jester/insert-newline-below ()
"Insert a newline below point."
(interactive)
(save-excursion
(move-end-of-line 1)
(insert "\n")))

(general-define-key
:states '(insert emacs)
:keymaps '(prog-mode-map conf-mode-map)
"<S-return>" 'jester/insert-newline-below)

;;----------------------------------------------------------------------------
;; move to bracket
;;----------------------------------------------------------------------------
Expand Down
16 changes: 4 additions & 12 deletions modes/init-elpa.el
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,11 @@


;;; Standard package repositories

(setq package-archives
(append '(
;; ("melpa-cn" . "https://elpa.emacs-china.org/melpa/")
;; ("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" . "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))
'(("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/")))



Expand Down
Loading

0 comments on commit 660ac9f

Please sign in to comment.