From 29d6092d4800f551e69054913e2f15ffb089af1b Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 31 Jan 2017 15:31:19 +0100 Subject: emacs: be more verbose on the explanation behind Evil mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- emacs/init.html | 202 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 142 insertions(+), 60 deletions(-) (limited to 'emacs/init.html') diff --git a/emacs/init.html b/emacs/init.html index e588ccf..10cfed1 100644 --- a/emacs/init.html +++ b/emacs/init.html @@ -4,7 +4,7 @@ mssola's GNU Emacs configuration - + @@ -803,7 +803,12 @@ Then, for keeping up with my projects I use the Projectile + Helm combination. (use-package helm-projectile :ensure t :config - (helm-projectile-on)) + (helm-projectile-on) + + ; Define M-p as a way to quickly list all the available projects. + (with-eval-after-load 'evil + (define-key evil-normal-state-map (kbd "M-p") + 'helm-projectile-switch-project))) @@ -1081,7 +1086,7 @@ whenever I use it, I want basic evil movement.

-That being said, I also extend dired with some handy tweaks. +I also extend dired with some handy tweaks.

@@ -1132,11 +1137,15 @@ from the mu4

Forgive me, Father, for I have sinned. I've been exposed to modal editing through Vim, and that has changed how I view editing for the foreseeable future. -Because of this, I use Evil. The following block includes some heavy-lifting so +Because of this, I use Evil. The following blocks include some heavy-lifting so Evil and GNU Emacs work without hitting each other, and it also includes some Evil extensions.

+

+First of all, let's define a function that will be called whenever Evil is loaded. +

+
(defun mssola-evil ()
@@ -1158,11 +1167,6 @@ Evil extensions.
   (define-key global-map (kbd "M-h") 'help-command)
   (fset 'help-command help-map)
 
-  ; Helm + Projectile shortcuts.
-  (with-eval-after-load 'helm-projectile
-    (define-key evil-normal-state-map (kbd "M-p")
-      'helm-projectile-switch-project))
-
   ; I use the Super key in combination with j & k to move around i3. Let's unset
   ; M- combos for these two fellows for whenever I misstype them.
   (global-unset-key (kbd "M-j"))
@@ -1203,8 +1207,16 @@ Evil extensions.
   (define-key evil-normal-state-map (kbd "C-s") 'save-buffer)
   (define-key evil-insert-state-map (kbd "C-s")
     (lambda () (interactive) (save-buffer) (evil-force-normal-state))))
+
+
+ +

+Now make sure that Evil is installed, and call the relevant configuration functions. +

+ +
-(use-package evil +
(use-package evil
   :ensure t
   :config
 
@@ -1222,54 +1234,108 @@ Evil extensions.
   (evil-set-initial-state 'debugger-mode 'normal)
   (evil-set-initial-state 'describe-mode 'normal)
   (evil-set-initial-state 'Buffer-menu-mode 'normal)
+
+
- (use-package evil-leader - :ensure t - :config - (global-evil-leader-mode) - (evil-leader/set-leader ",") - (setq evil-leader/in-all-states 1) - (evil-leader/set-key - "," 'back-to-indentation - "c" 'delete-window - "k" 'kill-buffer-and-window - "v" 'split-window-right - "V" (lambda () (interactive) (split-window-right) (other-window 1)) - "f" 'flycheck-list-errors - "e" 'eval-last-sexp - "b" 'view-buffer - "o" 'browse-url-at-point)) - - (use-package evil-surround - :ensure t - :config - (global-evil-surround-mode 1)) +

+If Evil was properly loaded, then make sure that the following Evil-related +packages are installed and configured as well. I start by defining the +evil-leader package, which brings the leader feature from +Vim into Evil. +

- (use-package evil-commentary - :ensure t - :config - (evil-commentary-mode t)) +
- (use-package evil-args - :ensure t - :config - ; Configuration taken from the documentation of evil-args. +
(use-package evil-leader
+  :ensure t
+  :config
+  (global-evil-leader-mode)
+  (evil-leader/set-leader ",")
+  (setq evil-leader/in-all-states 1)
+  (evil-leader/set-key
+    "," 'back-to-indentation
+    "c" 'delete-window
+    "k" 'kill-buffer-and-window
+    "v" 'split-window-right
+    "V" (lambda () (interactive) (split-window-right) (other-window 1))
+    "f" 'flycheck-list-errors
+    "e" 'eval-last-sexp
+    "b" 'view-buffer
+    "o" 'browse-url-at-point))
+
+
- ;; Bind evil-args text objects - (define-key evil-inner-text-objects-map "a" 'evil-inner-arg) - (define-key evil-outer-text-objects-map "a" 'evil-outer-arg) +

+Another handy Vim plugin that has made it into Evil is evil-surround, which +defines a new text object for surrounding characters (e.g. change a string from +having double quotes with single quotes in a single command). +

- ;; Bind evil-forward/backward-args - (define-key evil-normal-state-map "L" 'evil-forward-arg) - (define-key evil-normal-state-map "H" 'evil-backward-arg) - (define-key evil-motion-state-map "L" 'evil-forward-arg) - (define-key evil-motion-state-map "H" 'evil-backward-arg)) +
- (use-package evil-numbers - :ensure t - :config - (define-key evil-normal-state-map (kbd "C-a") 'evil-numbers/inc-at-pt) - (define-key evil-normal-state-map (kbd "C-c -") 'evil-numbers/dec-at-pt))) +
(use-package evil-surround
+  :ensure t
+  :config
+  (global-evil-surround-mode 1))
+
+
+ +

+Next is another Vim plugin that has been ported to Evil: evil-commentary. This +package defines a new motion for comments, which is bound to +gc. So, for example, gcc will comment +the current line, regardless of the programming language. +

+ +
+ +
(use-package evil-commentary
+  :ensure t
+  :config
+  (evil-commentary-mode t))
+
+
+ +

+Another cool package is evil-args which defines the argument text object. This +text object can be targeted with the a character, and we can move backward and +forward through arguments with H and L +respectively. +

+ +
+ +
(use-package evil-args
+  :ensure t
+  :config
+  ; Configuration taken from the documentation of evil-args.
+
+  ;; Bind evil-args text objects
+  (define-key evil-inner-text-objects-map "a" 'evil-inner-arg)
+  (define-key evil-outer-text-objects-map "a" 'evil-outer-arg)
+
+  ;; Bind evil-forward/backward-args
+  (define-key evil-normal-state-map "L" 'evil-forward-arg)
+  (define-key evil-normal-state-map "H" 'evil-backward-arg)
+  (define-key evil-motion-state-map "L" 'evil-forward-arg)
+  (define-key evil-motion-state-map "H" 'evil-backward-arg))
+
+
+ +

+Last but not least, evil-numbers brings a couple of bindings available to Vim +into Evil: C-a for increasing a number, and +C-c - for decreasing it (modified because +C-z is my escape sequence). +

+ +
+ +
(use-package evil-numbers
+  :ensure t
+  :config
+  (define-key evil-normal-state-map (kbd "C-a") 'evil-numbers/inc-at-pt)
+  (define-key evil-normal-state-map (kbd "C-c -") 'evil-numbers/dec-at-pt)))
 
@@ -2007,7 +2073,7 @@ I'm giving ERC a chance. First of all, I'm setting up basic stuff.

-Setup desktop notifications. +I want to have a desktop notification whenever someone mentions my name.

@@ -2033,18 +2099,23 @@ Setup desktop notifications.

-Add some helper packages and update the loaded ERC modules. +Use the erc-hl-nicks package, so highlight support for nicknames is better.

-
(add-hook 'erc-connect-pre-hook
-          (lambda (x) (erc-update-modules)))
-
-(use-package erc-hl-nicks
+
(use-package erc-hl-nicks
   :ensure t)
+
+
+ +

+Some extra cookies: allow ERC to display images and Youtube thumbnails. +

-(use-package erc-yt +
+ +
(use-package erc-yt
   :ensure t
   :init
   (with-eval-after-load 'erc
@@ -2058,6 +2129,17 @@ Add some helper packages and update the loaded ERC modules.
 
+

+At this point, we can safely update all the loaded ERC modules. +

+ +
+ +
(add-hook 'erc-connect-pre-hook
+          (lambda (x) (erc-update-modules)))
+
+
+

And now define a function to connect to both IRC servers.

@@ -2439,7 +2521,7 @@ along with this program. If not, see < -- cgit v1.2.3