Skip to content

Commit

Permalink
evil-goggles; richer elisp highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
JJPandari committed Aug 23, 2019
1 parent 862aa97 commit cdb2416
Show file tree
Hide file tree
Showing 31 changed files with 423 additions and 167 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "targets"]
path = extensions/targets
url = [email protected]:noctuid/targets.el.git
[submodule "elispfl"]
path = extensions/elispfl
url = [email protected]:cireu/elispfl.git
1 change: 1 addition & 0 deletions extensions/elispfl
Submodule elispfl added at 960ccb
9 changes: 6 additions & 3 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
;; Adjust garbage collection thresholds during startup, and thereafter
;;----------------------------------------------------------------------------
(let ((normal-gc-cons-threshold (* 20 1024 1024))
(init-gc-cons-threshold (* 128 1024 1024)))
(init-gc-cons-threshold (* 512 1024 1024)))
(setq gc-cons-threshold init-gc-cons-threshold)
(add-hook 'emacs-startup-hook
(lambda () (setq gc-cons-threshold normal-gc-cons-threshold)
Expand Down Expand Up @@ -61,6 +61,7 @@
(require 'init-flycheck)

(require 'init-ivy)
;; (require 'init-helm)
(require 'init-company)
(require 'init-yas)
(require 'init-windows)
Expand Down Expand Up @@ -90,10 +91,11 @@
;; ;; (require 'init-haskell)
;; (require 'init-ruby)
;; (require 'init-rails)
;; (require 'init-php)
;; (require 'init-sql)
(require 'init-yaml)
;; (require 'init-docker)
;; ;; (maybe-require-package 'nginx-mode)
(require 'init-docker)
(require 'init-nginx)
(require 'init-lua)
(require 'init-ahk)
(require 'init-dotenv)
Expand All @@ -111,6 +113,7 @@
(require 'init-chinese)
(require 'init-keyfreq)
(require 'init-edit-server)
(require 'init-player)
(require 'init-misc)

;; Extra packages which don't require any configuration
Expand Down
38 changes: 18 additions & 20 deletions modes/init-buffer.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
(setq initial-scratch-message "")

(jester/with-leader
"b b" 'switch-to-buffer
"b i" 'ibuffer
Expand All @@ -12,6 +10,24 @@
"<return>" 'jester/alternate-buffer
"m s" 'jester/switch-mode)

;;----------------------------------------------------------------------------
;; setup ibuffer.
;;----------------------------------------------------------------------------
(defun ibuffer-set-up-preferred-filters ()
(unless (eq ibuffer-sorting-mode 'filename/process)
(ibuffer-do-sort-by-filename/process)))

(add-hook 'ibuffer-hook 'ibuffer-set-up-preferred-filters)

(after-load 'ibuffer
;; Use human readable Size column instead of original one
(define-ibuffer-column size-h
(:name "Size" :inline t)
(cond
((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0)))
(t (format "%8d" (buffer-size))))))

;;----------------------------------------------------------------------------
;; switch *scratch* buffer
;;----------------------------------------------------------------------------
Expand Down Expand Up @@ -39,24 +55,6 @@ current window."
(not (eq buffer current-buffer)))
(mapcar #'car (window-prev-buffers window))))))

;;----------------------------------------------------------------------------
;; setup ibuffer.
;;----------------------------------------------------------------------------
(defun ibuffer-set-up-preferred-filters ()
(unless (eq ibuffer-sorting-mode 'filename/process)
(ibuffer-do-sort-by-filename/process)))

(add-hook 'ibuffer-hook 'ibuffer-set-up-preferred-filters)

(after-load 'ibuffer
;; Use human readable Size column instead of original one
(define-ibuffer-column size-h
(:name "Size" :inline t)
(cond
((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0)))
(t (format "%8d" (buffer-size))))))

;;----------------------------------------------------------------------------
;; kill this buffer.
;;----------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions modes/init-chinese.el
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
:bind ("C-c y" . youdao-dictionary-search-at-point+)
)


(use-package pyim
:demand t
:config
Expand All @@ -31,6 +32,7 @@
;; ("C-;" . pyim-delete-word-from-personal-buffer)
))


(use-package pyim-wbdict
:demand t
:after pyim
Expand Down
8 changes: 7 additions & 1 deletion modes/init-company.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@
(use-package company-tabnine
:demand t
:config
(push 'company-tabnine company-backends))
(setq jester-company-backends-with-tabnine (cons 'company-tabnine company-backends))
(defun jester/use-tabnine-for-major-mode (major-mode)
"add tabnine to `COMPANY-BACKENDS' in `MAJOR-MODE'."
(add-hook (intern (format "%s-hook" major-mode))
(lambda () (setq-local company-backends jester-company-backends-with-tabnine))))
(dolist (mode '(js2-mode css-mode less-css-mode scss-mode))
(jester/use-tabnine-for-major-mode mode)))


;; (use-package company-quickhelp
Expand Down
24 changes: 20 additions & 4 deletions modes/init-docker.el
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
(when (maybe-require-package 'docker)
(use-package docker
:init
(jester/with-leader "d d" 'docker)
:commands docker
:config
(fullframe docker-images tablist-quit)
(fullframe docker-machines tablist-quit)
(fullframe docker-volumes tablist-quit)
(fullframe docker-networks tablist-quit)
(fullframe docker-containers tablist-quit))
(maybe-require-package 'dockerfile-mode)
(maybe-require-package 'docker-compose-mode)
(fullframe docker-containers tablist-quit)
;; TODO copy emacs state binding to motion state
(evil-set-initial-state 'docker-image-mode 'emacs)
(evil-set-initial-state 'docker-machine-mode 'emacs)
(evil-set-initial-state 'docker-volume-mode 'emacs)
(evil-set-initial-state 'docker-network-mode 'emacs)
(evil-set-initial-state 'docker-container-mode 'emacs))

(use-package dockerfile-mode
;; TODO auto upper-case first word on line?
:init
(add-hook! 'dockerfile-mode-hook (setq tab-width 0))
:mode "\\Dockerfile\\'")

(use-package docker-compose-mode)


(provide 'init-docker)
105 changes: 97 additions & 8 deletions modes/init-editing-utils.el
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
;; TODO auto `else' when use space after if{
;; }
;; TODO pad-operator
;;----------------------------------------------------------------------------
;; Some basic preferences
;;----------------------------------------------------------------------------
Expand All @@ -24,9 +27,10 @@
recentf-max-saved-items 1000)

(electric-indent-mode -1) ;; this is global
;; TODO undo: group to previous ops for evil
(use-package aggressive-indent
:custom (aggressive-indent-region-function 'evil-indent "also convert tab/space when indent")
:hook (after-init . aggressive-indent-global-mode))
;; TODO 'aggressive-indent-dont-indent-if: in web-mode indent others but not html

(require 'recentf)
(add-to-list 'recentf-exclude (list "/tmp/" "/ssh:" "COMMIT_EDITMSG\\'"
Expand Down Expand Up @@ -69,6 +73,16 @@

(use-package string-inflection)


(use-package subword
:ensure nil
:init
(general-define-key
:states '(operator)
"x" 'subword-forward
"z" 'subword-backward)
:commands (subword-forward subword-backward))

;;----------------------------------------------------------------------------
;; kill back to indentation
;;----------------------------------------------------------------------------
Expand Down Expand Up @@ -142,9 +156,9 @@
(indent-for-tab-command))

(general-define-key
:states '(normal)
:states '(normal visual)
"z k" 'jester/move-line-up
"z j" #'jester/move-line-down)
"z j" 'jester/move-line-down)

;;----------------------------------------------------------------------------
;; like web-mode-on-post-command
Expand Down Expand Up @@ -285,10 +299,6 @@ otherwise move to before semicolon."
:states '(insert emacs)
:keymaps '(web-mode-map js2-mode-map coffee-mode-map)
"C-t" 'jester/insert-this.)
;; TODO
;; foo "1 xx" -> foo {
;; bar: 12 bar: 12
;; }

;;----------------------------------------------------------------------------
;; insert a curly block
Expand All @@ -312,7 +322,6 @@ Threat is as function body when from endline before )"
;;----------------------------------------------------------------------------
(evil-define-motion jester/backward-bracket (count)
"Move backward to a (, [ or {."
;; TODO not really exclusive
;; TODO enable lispyville everywhere
:type exclusive
(setq count (or count 1))
Expand All @@ -335,5 +344,85 @@ Threat is as function body when from endline before )"
"(" 'backward-up-list
")" 'up-list)

;;----------------------------------------------------------------------------
;; move to paragraph begin/end
;;----------------------------------------------------------------------------
(evil-define-motion jester/forward-paragraph (count)
"Move to paragraph end, line-wise."
:type line
(interactive "p")
(forward-paragraph count)
(previous-line))

(evil-define-motion jester/backward-paragraph (count)
"Move to paragraph start, line-wise."
:type line
(interactive "p")
(backward-paragraph count)
(next-line))

(general-define-key
:states '(normal visual motion operator)
"[" 'jester/backward-paragraph
"]" 'jester/forward-paragraph)

;;----------------------------------------------------------------------------
;; narrow
;;----------------------------------------------------------------------------
;; https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-misc.el
(defun line-number-at-position (pos)
"Returns the line number for position `POS'."
(save-restriction
(widen)
(save-excursion
(goto-char pos)
(+ 1 (current-line)))))

(defun narrow-to-region-indirect-buffer-maybe (start end use-indirect-buffer)
"Indirect buffer could multiple widen on same file."
(if (region-active-p) (deactivate-mark))
(if use-indirect-buffer
(with-current-buffer
(jester/eval-with-display-in-same-window
(clone-indirect-buffer
(generate-new-buffer-name
(format "%s-indirect-:%s-:%s"
(buffer-name) (line-number-at-position start) (line-number-at-position end)))
'display))
(narrow-to-region start end)
(goto-char (point-min)))
(narrow-to-region start end)))

;; https://gist.github.com/mwfogleman/95cc60c87a9323876c6c
(defun narrow-or-widen-dwim (&optional use-indirect-buffer)
"If the buffer is narrowed, it widens.
Otherwise, it narrows to region, or Org subtree.
If use-indirect-buffer is not nil, use `indirect-buffer' to hold the widen content."
(interactive "P")
(cond ((buffer-narrowed-p) (widen))
((region-active-p)
(narrow-to-region-indirect-buffer-maybe (region-beginning)
(region-end)
use-indirect-buffer))
((equal major-mode 'org-mode)
(org-narrow-to-subtree))
((derived-mode-p 'diff-mode)
(let* (b e)
(save-excursion
;; If the (point) is already beginning or end of file diff,
;; the `diff-beginning-of-file' and `diff-end-of-file' return nil
(setq b (progn (diff-beginning-of-file) (point)))
(setq e (progn (diff-end-of-file) (point))))
(when (and b e (< b e))
(narrow-to-region-indirect-buffer-maybe b e use-indirect-buffer))))
((derived-mode-p 'prog-mode)
(mark-defun)
(narrow-to-region-indirect-buffer-maybe (region-beginning)
(region-end)
use-indirect-buffer))
(t (error "Please select a region to narrow to"))))

(jester/with-leader "n n" 'narrow-or-widen-dwim)


(provide 'init-editing-utils)
Loading

0 comments on commit cdb2416

Please sign in to comment.