+a lot of changes

Firstly, some org stuff to make everything flat (no indents).

Secondly, a lot of new packages including general.

Using general to manage all binds now.

Reorganised code quite a bit
This commit is contained in:
2020-08-06 15:15:21 +01:00
parent 373518c3b1
commit 28da4f0634

View File

@@ -136,36 +136,38 @@
default-directory)))
(start-process-shell-command "" nil (format "cd %s; ctags -Re ." root))))
#+END_SRC
* Keybindings
** Global map
Any functions that are already loaded, set them to the global map.
* General
Setup general, a good package for defining keys.
#+BEGIN_SRC emacs-lisp
(bind-keys
:map global-map
("<menu>" . nil)
("M-v" . (lambda () (interactive) (dx:newline 1)))
("M-V" . (lambda () (interactive) (dx:newline)))
("M-z" . mark-whole-buffer)
("C-x h" . next-buffer)
("C-x l" . previous-buffer)
("C-c !" . async-shell-command)
("C-c c" . compile)
("C-c t" . eshell)
("M-s i" . imenu)
("M-n f" . narrow-to-defun)
("M-n w" . widen)
("M-n r" . narrow-to-region))
#+END_SRC
** Menu map
Any keys I want to map to <menu>, the weird little menu interaction button on some keyboards.
#+BEGIN_SRC emacs-lisp
(bind-keys
:prefix "<menu>"
:prefix-map dx:menu-map
("<menu>" . execute-extended-command)
("p" . (lambda () (interactive) (find-file (concat user-emacs-directory "config.org"))))
("#" . (lambda () (interactive) (projectile-find-file)))
("." . imenu))
(use-package general
:config
(general-def 'normal global-map "SPC" nil)
(general-def 'normal global-map
"M-V" #'dx:newline
"M-v" #'(lambda () (interactive) (dx:newline 1)))
(general-create-definer leader
:states 'normal
:keymaps 'override
:prefix "SPC")
(leader
"SPC" #'execute-extended-command
"u" #'universal-argument
"si" #'imenu
"h" #'help-command)
(leader
:infix "b"
"d" #'kill-this-buffer
"i" #'ibuffer
"b" #'switch-to-buffer)
(leader
:infix "f"
"f" #'find-file
"s" #'save-buffer
"p" #'(lambda () (interactive) (find-file (concat user-emacs-directory "config.org")))))
#+END_SRC
* Evil
** Evil default
@@ -178,18 +180,8 @@
:config
(evil-mode +1)
(evil-define-key 'normal global-map
"TAB" #'evil-jump-item
"SPC" nil)
(evil-define-key 'visual 'emacs-lisp-mode-map "gr" #'eval-region)
(bind-keys
:map evil-normal-state-map
:prefix "SPC"
:prefix-map +evil/leader-map
("f" . find-file)
("s" . save-buffer)
("q" . save-buffers-kill-terminal)
("i" . imenu)
("b" . switch-to-buffer)))
"TAB" #'evil-jump-item)
(evil-define-key 'visual 'emacs-lisp-mode-map "gr" #'eval-region))
#+END_SRC
** Evil surround
#+BEGIN_SRC emacs-lisp
@@ -228,7 +220,6 @@
(defvar evil-mc-key-map (make-sparse-keymap))
(define-prefix-command 'dx:evil-mc-map)
(bind-key "gz" dx:evil-mc-map evil-normal-state-map)
(bind-key "gz" dx:evil-mc-map evil-visual-state-map)
:config
(global-evil-mc-mode +1)
(defun dx:evil-mc-cursor-here ()
@@ -243,14 +234,143 @@
(use-package evil-collection
:after evil)
#+END_SRC
* IBuffer
* Ivy
Ivy is a completion framework for Emacs, and my preferred (sometimes second favourite) one.
It has a great set of features with little to no pain with setting up.
** Ivy
Setup for ivy, in preparation for counsel.
Turn on ivy-mode just after init.
Setup vim-like bindings for the minibuffer ("C-(j|k)" for down|up the selection list)
Also setup evil-collection for ivy.
#+BEGIN_SRC emacs-lisp
(use-package ibuffer
:bind ("<menu> ," . ibuffer)
(use-package ivy
:hook (after-init . ivy-mode)
:after evil-collection
:bind (:map ivy-minibuffer-map
("C-j" . ivy-next-line-or-history)
("C-k" . ivy-previous-line-or-history)
:map ivy-switch-buffer-map
("C-j" . ivy-next-line-or-history)
("C-k" . ivy-previous-line-or-history))
:general
(:keymaps 'ivy-minibuffer-map
"C-c C-e" #'ivy-occur)
:config
(evil-collection-ibuffer-setup))
(require 'counsel nil t)
(setq ivy-height 10
ivy-wrap t
ivy-fixed-height-minibuffer t
ivy-use-virtual-buffers nil
ivy-virtual-abbreviate 'full
ivy-on-del-error-function #'ignore
ivy-use-selectable-prompt t
ivy-initial-inputs-alist nil)
(evil-collection-ivy-setup))
#+END_SRC
** Counsel
Setup for counsel.
Load after ivy and helpful.
Bind:
- Swiper to "C-s"
- Switch buffer to "C-x b"
- Counsel ripgrep to "M-s r" (search namespace)
Along with that, set the help function and variable functions to their helpful counterparts.
#+BEGIN_SRC emacs-lisp
(use-package counsel
:defer t
:general
(leader
:infix "s"
"s" #'counsel-grep-or-swiper)
:init
(general-def
[remap describe-function] #'counsel-describe-function
[remap describe-variable] #'counsel-describe-variable
[remap describe-bindings] #'counsel-descbinds
[remap describe-face] #'counsel-faces
[remap execute-extended-command] #'counsel-M-x
[remap find-file] #'counsel-find-file
[remap imenu] #'counsel-imenu
[remap load-theme] #'counsel-load-theme)
:config
(setq ivy-initial-inputs-alist nil)
(setq counsel-describe-function-function #'helpful-callable
counsel-describe-variable-function #'helpful-variable))
#+END_SRC
** Counsel etags
Counsel etags allows me to search generated tag files for tags.
I already have a function defined [[*Generate tags][here]] to generate the tags, so it's just searching them which I find to be a bit of a hassle, and where this package comes in.
#+BEGIN_SRC emacs-lisp
(use-package counsel-etags
:after counsel
:bind ("M-s t" . counsel-etags-find-tag))
#+END_SRC
* Avy
Setup avy with leader.
#+BEGIN_SRC emacs-lisp
(use-package avy
:after evil
:general
(leader
:infix "s"
"l" #'avy-goto-line
"g" #'avy-goto-char-2))
#+END_SRC
* Projectile
Setup projectile, along with the tags command.
Also bind "C-c C-p" to the projectile command map for quick access.
#+BEGIN_SRC emacs-lisp
(use-package projectile
:after evil
:hook (prog-mode . projectile-mode)
:init
(setq projectile-tags-command "ctags -Re -f \"%s\" %s \"%s\"")
:config
(projectile-global-mode))
#+END_SRC
** Counsel projectile
Counsel projectile provides the ivy interface to projectile commands, which is really useful.
#+BEGIN_SRC emacs-lisp
(use-package counsel-projectile
:after (projectile counsel)
:config
(counsel-projectile-mode +1))
#+END_SRC
* Mail
** Notmuch
#+BEGIN_SRC emacs-lisp
(setq +mail/signature "---------------\nAryadev Chavali")
(use-package notmuch
:commands notmuch
:custom
((notmuch-show-logo nil)
(message-signature +mail/signature)
(mail-signature +mail/signature))
:init
(defun +mail/sync-mail ()
"Sync mail via mbsync."
(interactive)
(start-process-shell-command "" nil "mbsync -a"))
:config
(evil-collection-notmuch-setup))
#+END_SRC
** Smtpmail
#+BEGIN_SRC emacs-lisp
(use-package smtpmail
:commands mail-send
:after notmuch
:custom
((smtpmail-smtp-server "mail.aryadevchavali.com")
(smtpmail-smtp-user "aryadev")
(smtpmail-smtp-service 587)
(smtpmail-stream-type 'starttls))
:init
(setq send-mail-function #'smtpmail-send-it
message-send-mail-function #'smtpmail-send-it))
#+END_SRC
* Dired
Setup for dired.
Firstly, as it's an inbuilt package don't let straight try and download it.
@@ -261,25 +381,64 @@
(use-package dired
:straight nil
:hook (dired-mode . dired-hide-details-mode)
:bind (:map +evil/leader-map
("d" . dired-jump))
:bind-keymap* ("C-c d" . dx:dired-map)
:after evil-collection
:init
(defvar dx:dired-map (make-sparse-keymap) "dx:dired-map")
:general
(leader
:infix "d"
"f" #'find-dired
"D" #'dired-other-window
"d" #'dired-jump)
:config
(bind-keys
:map dx:dired-map
("f" . find-dired)
("D" . dired-other-window)
("d" . dired-jump))
(evil-collection-dired-setup))
#+END_SRC
* Hydra
Use hydras for stuff that I use often, currently buffer manipulation
#+BEGIN_SRC emacs-lisp
(use-package hydra
:after evil
:init
(defun dx:kill-defun ()
"Mark defun then kill it."
(interactive)
(mark-defun)
(delete-active-region t))
(defun dx:paste-section ()
"Paste the current kill-region content above section."
(interactive)
(open-line 1)
(yank))
:config
(defhydra hydra-buffer (evil-normal-state-map "SPC b")
"buffer-hydra"
("j" next-buffer)
("k" previous-buffer)
("c" kill-this-buffer))
(defhydra hydra-code-manipulator (global-map "C-x c")
"code-manip"
("j" evil-forward-section-begin)
("k" evil-backward-section-begin)
("m" mark-defun)
("d" dx:kill-defun)
("p" dx:paste-section)
("TAB" evil-toggle-fold)))
#+END_SRC
* IBuffer
#+BEGIN_SRC emacs-lisp
(use-package ibuffer
:after evil-collection
:config
(evil-collection-ibuffer-setup))
#+END_SRC
* Helpful
Basic setup, will be fully integrated in counsel.
#+BEGIN_SRC emacs-lisp
(use-package helpful
:commands (helpful-callable helpful-variable))
:commands (helpful-callable helpful-variable)
:init
(evil-define-key 'normal helpful-mode-map "q" #'quit-window))
#+END_SRC
* Which-key
Pretty simple, just activate after init.
@@ -287,19 +446,6 @@
(use-package which-key
:hook (after-init . which-key-mode))
#+END_SRC
* Avy
Avy is an incredibly useful package that I have just started to understand.
For now, I have two bindings for =avy-goto-line= and =avy-goto-char-2= as I use them often.
#+BEGIN_SRC emacs-lisp
(use-package avy
:bind (("M-g" . #'avy-goto-char-2)
("M-l" . #'avy-goto-line)))
#+END_SRC
* Hydra
I haven't found a use for it yet, so don't tangle this.
#+BEGIN_SRC emacs-lisp :tangle no
(use-package hydra)
#+END_SRC
* Yasnippet
Yasnippet is a great package for snippets, which I use heavily in programming and org-mode.
I setup here the global mode for yasnippet and a collection of snippets for ease of use.
@@ -308,8 +454,11 @@
#+BEGIN_SRC emacs-lisp
(use-package yasnippet
:after evil
:hook (after-init . yas-global-mode)
:bind ("C-c i" . yas-insert-snippet))
:hook ((prog-mode . yas-minor-mode)
(text-mode . yas-minor-mode))
:general
(leader
"i" #'yas-insert-snippet))
#+END_SRC
** Yasnippet snippets
Collection of snippets, activate after yasnippet has been loaded.
@@ -327,69 +476,17 @@
(key-chord-define evil-insert-state-map "jk" #'evil-normal-state)
(key-chord-mode +1))
#+END_SRC
* Ivy
Ivy is a completion framework for Emacs, and my preferred (sometimes second favourite) one.
It has a great set of features with little to no pain with setting up.
** Ivy
Setup for ivy, in preparation for counsel.
Turn on ivy-mode just after init.
Setup vim-like bindings for the minibuffer ("C-(j|k)" for down|up the selection list)
Also setup evil-collection for ivy.
#+BEGIN_SRC emacs-lisp
(use-package ivy
:after evil-collection
:hook (after-init . ivy-mode)
:bind (:map ivy-minibuffer-map
("C-j" . ivy-next-line-or-history)
("C-k" . ivy-previous-line-or-history)
:map ivy-switch-buffer-map
("C-j" . ivy-next-line-or-history)
("C-k" . ivy-previous-line-or-history))
:config
(evil-collection-ivy-setup))
#+END_SRC
** Counsel
Setup for counsel.
Load after ivy and helpful.
Bind:
- Swiper to "C-s"
- Switch buffer to "C-x b"
- Counsel ripgrep to "M-s r" (search namespace)
Along with that, set the help function and variable functions to their helpful counterparts.
#+BEGIN_SRC emacs-lisp
(use-package counsel
:after (ivy helpful)
:bind (("C-s" . counsel-grep-or-swiper)
("C-x b" . counsel-switch-buffer))
:config
(setq ivy-initial-inputs-alist nil
counsel-describe-function-function #'helpful-callable
counsel-describe-variable-function #'helpful-variable))
#+END_SRC
** Counsel etags
Counsel etags allows me to search generated tag files for tags.
I already have a function defined [[*Generate tags][here]] to generate the tags, so it's just searching them which I find to be a bit of a hassle, and where this package comes in.
#+BEGIN_SRC emacs-lisp
(use-package counsel-etags
:after counsel
:bind ("M-s t" . counsel-etags-find-tag))
#+END_SRC
* Ripgrep
The ripgrep package provides utilities to grep projects and files for strings via the rg tool.
Though [[*Ivy][ivy]] comes with =counsel-rg= using it makes me dependent on the ivy framework, and this configuration is intentionally built to be modular and switchable.
#+BEGIN_SRC emacs-lisp
(use-package rg
:after evil
:bind (("M-s r" . rg)
:map +evil/leader-map
("r" . rg)
:map rg-mode-map
("]]" . rg-next-file)
("[[" . rg-prev-file))
:general
(leader "r" #'rg)
(:keymaps 'rg-mode-map
"]]" #'rg-next-file
"[[" #'rg-prev-file)
:init
(setq rg-group-result t
rg-hide-command t
@@ -398,41 +495,14 @@
rg-custom-type-aliases nil
rg-default-alias-fallback "all"))
#+END_SRC
* Projectile
** Projectile default
Setup projectile, along with the tags command.
Also bind "C-c C-p" to the projectile command map for quick access.
#+BEGIN_SRC emacs-lisp
(use-package projectile
:after evil
:hook (prog-mode . projectile-mode)
:bind (:map +evil/leader-map
("p" . projectile-switch-buffer))
:bind-keymap* ("C-c C-p" . projectile-command-map)
:init
(setq projectile-tags-command "ctags -Re -f \"%s\" %s \"%s\"")
:config
(projectile-global-mode))
#+END_SRC
** Counsel projectile
Counsel projectile provides the ivy interface to projectile commands, which is really useful.
#+BEGIN_SRC emacs-lisp
(use-package counsel-projectile
:after (projectile counsel)
:config
(counsel-projectile-mode +1))
#+END_SRC
* Magit
Magit is *the* git porcelain for Emacs, which perfectly encapsulates the git cli.
In this case, I just need to setup the bindings for it.
As magit will definitely load after evil (as it must be run by a binding, and evil will load after init), I can use evil-collection freely.
#+BEGIN_SRC emacs-lisp
(use-package magit
:bind (("C-x g g" . magit-status)
("C-x g c" . magit-clone)
("C-x g l" . magit-log)
:map +evil/leader-map
("g" . magit-status)))
:general
(leader "g" #'magit-status))
(use-package evil-magit
:after magit)
@@ -455,7 +525,6 @@
I've also bound "C-c r" to elfeed for loading the system.
#+BEGIN_SRC emacs-lisp
(use-package elfeed
:bind ("C-c r" . elfeed)
:init
(setq +rss/feed-urls
'(("Arch Linux" "https://www.archlinux.org/feeds/news/" Linux)
@@ -469,7 +538,7 @@
("Fredrik Knusden" "https://www.youtube.com/feeds/videos.xml?channel_id=UCbWcXB0PoqOsAvAdfzWMf0w" YouTube Stories)
("Barely Sociable" "https://www.youtube.com/feeds/videos.xml?channel_id=UC9PIn6-XuRKZ5HmYeu46AIw" YouTube Stories)
("Atrocity Guide" "https://www.youtube.com/feeds/videos.xml?channel_id=UCn8OYopT9e8tng-CGEWzfmw" YouTube Stories)
("Phillip Defranco" "https://www.youtube.com/feeds/videos.xml?channel_id=UClFSU9_bUb4Rc6OYfTt5SPw" YouTube News)
("Philip Defranco" "https://www.youtube.com/feeds/videos.xml?channel_id=UClFSU9_bUb4Rc6OYfTt5SPw" YouTube News)
("Hacker News" "http://morss.aryadevchavali.com/news.ycombinator.com/rss" Social)
("Hacker Factor" "https://www.hackerfactor.com/blog/index.php?/feeds/index.rss2" Social)
("BBC Top News" "http://morss.aryadevchavali.com/feeds.bbci.co.uk/news/rss.xml" News)
@@ -480,7 +549,7 @@
(evil-define-key 'normal elfeed-search-mode-map "gr" #'elfeed-update)
(evil-define-key 'normal elfeed-search-mode-map "s" #'elfeed-search-live-filter)
(evil-define-key 'normal elfeed-search-mode-map "<return>" #'elfeed-search-show-entry)
(setq elfeed-feeds (mapc #'(lambda (item) (append (list (nth 1 item)) (cdr (cdr item)))) +rss/feed-urls)))
(setq elfeed-feeds (cl-map 'list #'(lambda (item) (append (list (nth 1 item)) (cdr (cdr item)))) +rss/feed-urls)))
#+END_SRC
* Org mode
** Org default with evil
@@ -492,7 +561,21 @@
:bind (:map org-mode-map
([remap imenu] . counsel-org-goto))
:custom
(org-src-window-setup 'current-window))
((org-edit-src-content-indentation 0)
(org-src-window-setup 'current-window)
(org-indirect-buffer-display 'current-window)
(org-eldoc-breadcrumb-separator "")
(org-enforce-todo-dependencies t)
(org-entities-user '(("flat" "\\flat" nil "" "" "266D" "") ("sharp" "\\sharp" nil "" "" "266F" "")))
(org-fontify-quote-and-verse-blocks t)
(org-fontify-whole-heading-line t)
(org-footnote-auto-label 'plain)
(org-hide-leading-stars t)
(org-image-actual-width nil)
(org-priority-faces '((?A . error) (?B . warning) (?C . success)))
(org-startup-indented t)
(org-tags-column 0)
(org-use-sub-superscripts '{})))
(use-package evil-org
:hook (org-mode . evil-org-mode))
@@ -536,7 +619,10 @@
("magit-diff:.*"
(display-buffer-in-side-window)
(side . right)
(slot . -2)
(window-width . 0.5))
("magit-log:.*"
(display-buffer-in-side-window)
(side . right)
(window-width . 0.5))
("\\*compilation\\*"
(display-buffer-in-side-window)
@@ -562,12 +648,20 @@
Smartparens is a smarter electric-parens, it's much more aware of stuff and easier to use.
#+BEGIN_SRC emacs-lisp
(use-package smartparens
:hook (prog-mode . smartparens-mode)
:after evil
:config
(setq sp-highlight-pair-overlay nil
sp-highlight-wrap-overlay t
sp-highlight-wrap-tag-overlay t)
(smartparens-global-mode))
(let ((unless-list '(sp-point-before-word-p
sp-point-after-word-p
sp-point-before-same-p)))
(sp-pair "'" nil :unless unless-list)
(sp-pair "\"" nil :unless unless-list))
(sp-local-pair sp-lisp-modes "(" ")" :unless '(:rem sp-point-before-same-p))
(require 'smartparens-config))
#+END_SRC
** Show-paren-mode
Show parenthesis for Emacs
@@ -580,10 +674,7 @@
:hook (prog-mode . eldoc-mode))
(use-package eldoc-box
:hook (eglot--managed-mode . eldoc-box-hover-mode)
:custom
((eldoc-box-max-pixel-height 15)
(eldoc-box-max-pixel-width 15)))
:hook (eldoc-mode . eldoc-box-hover-mode))
#+END_SRC
** Eglot
@@ -606,7 +697,6 @@
#+BEGIN_SRC emacs-lisp
(use-package flycheck
:commands flycheck-mode
:bind ("C-c x" . +flycheck/list-errors-load-flycheck)
:config
(defun +flycheck/list-errors-load-flycheck ()
"Load flycheck if not available, then list errors."
@@ -635,8 +725,8 @@
Finally, add a user style that mimics the Microsoft guidelines for C# (open braces everywhere).
#+BEGIN_SRC emacs-lisp
(use-package cc-mode
:hook (c-mode . +dx:activate-tabs)
:hook (c++-mode . +dx:activate-tabs)
:hook (c-mode . dx:activate-tabs)
:hook (c++-mode . dx:activate-tabs)
:init
(setq-default c-basic-offset 2)
(setq c-default-style '((java-mode . "java")
@@ -671,3 +761,78 @@
(bind-key "C-c '" #'clang-format-region c-mode-map)
(bind-key "C-c '" #'clang-format-region c++-mode-map))
#+END_SRC
** Emacs lisp
#+BEGIN_SRC emacs-lisp
(with-eval-after-load "lisp-mode"
(defun +modded/lisp-indent-function (indent-point state)
"This function is the normal value of the variable `lisp-indent-function'.
The function `calculate-lisp-indent' calls this to determine
if the arguments of a Lisp function call should be indented specially.
INDENT-POINT is the position at which the line being indented begins.
Point is located at the point to indent under (for default indentation);
STATE is the `parse-partial-sexp' state for that position.
If the current line is in a call to a Lisp function that has a non-nil
property `lisp-indent-function' (or the deprecated `lisp-indent-hook'),
it specifies how to indent. The property value can be:
,* `defun', meaning indent `defun'-style
\(this is also the case if there is no property and the function
has a name that begins with \"def\", and three or more arguments);
,* an integer N, meaning indent the first N arguments specially
(like ordinary function arguments), and then indent any further
arguments like a body;
,* a function to call that returns the indentation (or nil).
`lisp-indent-function' calls this function with the same two arguments
that it itself received.
This function returns either the indentation to use, or nil if the
Lisp function does not specify a special indentation."
(let ((normal-indent (current-column))
(orig-point (point)))
(goto-char (1+ (elt state 1)))
(parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
(cond
;; car of form doesn't seem to be a symbol, or is a keyword
((and (elt state 2)
(or (not (looking-at "\\sw\\|\\s_"))
(looking-at ":")))
(if (not (> (save-excursion (forward-line 1) (point))
calculate-lisp-indent-last-sexp))
(progn (goto-char calculate-lisp-indent-last-sexp)
(beginning-of-line)
(parse-partial-sexp (point)
calculate-lisp-indent-last-sexp 0 t)))
;; Indent under the list or under the first sexp on the same
;; line as calculate-lisp-indent-last-sexp. Note that first
;; thing on that line has to be complete sexp since we are
;; inside the innermost containing sexp.
(backward-prefix-chars)
(current-column))
((and (save-excursion
(goto-char indent-point)
(skip-syntax-forward " ")
(not (looking-at ":")))
(save-excursion
(goto-char orig-point)
(looking-at ":")))
(save-excursion
(goto-char (+ 2 (elt state 1)))
(current-column)))
(t
(let ((function (buffer-substring (point)
(progn (forward-sexp 1) (point))))
method)
(setq method (or (function-get (intern-soft function)
'lisp-indent-function)
(get (intern-soft function) 'lisp-indent-hook)))
(cond ((or (eq method 'defun)
(and (null method)
(> (length function) 3)
(string-match "\\`def" function)))
(lisp-indent-defform state indent-point))
((integerp method)
(lisp-indent-specform method state
indent-point normal-indent))
(method
(funcall method indent-point state))))))))
(add-hook 'emacs-lisp-mode-hook #'(lambda () (interactive) (setq-local lisp-indent-function #'+modded/lisp-indent-function))))
#+END_SRC