From 08bb43b31a206b56069df0fafc206941947be6ec Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 10 Feb 2017 10:03:06 +0100 Subject: emacs: general fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - projectile: removed the format definition. I didn't know that the default format already took into account clashes between files from different projects. This way I don't need other packages like =uniquify=. - crux: fixed bindings. - magit: added a binding for =magit-blame= and improved the documentation. - ohers: added the =mssola-face-at-point= function Signed-off-by: Miquel Sabaté Solà --- emacs/init.html | 118 +++++++++++++++++++++++++++++++++++++++++--------------- emacs/init.org | 104 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 157 insertions(+), 65 deletions(-) diff --git a/emacs/init.html b/emacs/init.html index f79b590..e751911 100644 --- a/emacs/init.html +++ b/emacs/init.html @@ -4,7 +4,7 @@ mssola's GNU Emacs configuration - + @@ -425,6 +425,28 @@ I've hacked my own theme called soria<
(load-theme 'soria t)
 
+ +

+When hacking your own theme, sometimes you want to know what face is the one +that you see on the screen right now. This function from @thblt allows me to +get exactly that: +

+ +
+ +
(defun mssola-face-at-point (pos)
+  "Writes a message with the name of the face at the current point.  The POS
+  argument contains the current position of the cursor."
+
+  (interactive "d")
+
+  (let ((face (or (get-char-property (point) 'read-face-name)
+                  (get-char-property (point) 'face))))
+    (if face (message "Face: %s" face) (message "No face at %d" pos))))
+
+(global-set-key (kbd "C-c f") 'mssola-face-at-point)
+
+
@@ -790,9 +812,7 @@ Then, for keeping up with my projects I use the Projectile + Helm combination.
(use-package projectile
   :ensure t
   :config
-  (projectile-mode 1)
-  (setq projectile-mode-line
-    '(:eval (format " %s" (projectile-project-name)))))
+  (projectile-mode 1))
 
 (use-package helm
   :ensure t
@@ -1381,34 +1401,67 @@ certainly useful for some common tasks (I guess that I still need some learning)
 
(use-package magit
   :ensure t
   :config
+
+ - ; Proper initial states. - (with-eval-after-load 'evil - (add-hook 'git-commit-mode-hook 'evil-insert-state) - (evil-set-initial-state 'magit-log-edit-mode 'insert)) +

+In some cases normal mode is not the right mode (e.g. commit mode). For these +cases, set the proper default mode. +

- ; When showing the status, hide the usually-redundant "branch" section and - ; show the rest. - (add-hook 'magit-section-set-visibility-hook - '(lambda (section) - (if (string= (magit-section-type section) "branch") - 'hide - 'show))) +
- (with-eval-after-load 'evil-leader - (evil-leader/set-key "s" 'magit-status) +
(with-eval-after-load 'evil
+  (add-hook 'git-commit-mode-hook 'evil-insert-state)
+  (evil-set-initial-state 'magit-log-edit-mode 'insert))
+
+
+ +

+When showing the status, hide the usually-redundant "branch" section and show +the rest. +

- (use-package evil-magit - :ensure t - :config +
+ +
(add-hook 'magit-section-set-visibility-hook
+          '(lambda (section)
+             (if (string= (magit-section-type section) "branch")
+                 'hide
+               'show)))
+
+
+ +

+Set a key binding for magit-blame. +

+ +
+ +
(global-set-key (kbd "C-c b") 'magit-blame)
+
+
- ; The magit + evil-magit combo messes up some chords, let's fix this. - (evil-define-key 'normal magit-mode-map - "\C-h" 'evil-window-left - "\C-l" 'evil-window-right - "\C-j" 'evil-window-down - "\C-k" 'evil-window-up - "\M-p" 'helm-projectile-switch-project)))) +

+And repair some key bindings from Evil mode. +

+ +
+ +
(with-eval-after-load 'evil-leader
+  (evil-leader/set-key "s" 'magit-status)
+
+  (use-package evil-magit
+    :ensure t
+    :config
+
+    ; The magit + evil-magit combo messes up some chords, let's fix this.
+    (evil-define-key 'normal magit-mode-map
+      "\C-h" 'evil-window-left
+      "\C-l" 'evil-window-right
+      "\C-j" 'evil-window-down
+      "\C-k" 'evil-window-up
+      "\M-p"  'helm-projectile-switch-project))))
 
@@ -2605,13 +2658,16 @@ too many things into my leader and these shortcuts look sensible to me).
(use-package crux
   :ensure t
-  :bind (("C-c d" . crux-delete-file-and-buffer)
-         ("C-c r" . crux-rename-file-and-buffer)
-         ("C-c o" . crux-open-with)))
+  :config
+
+  (global-set-key (kbd "C-c d") 'crux-delete-file-and-buffer)
+  (global-set-key (kbd "C-c r") 'crux-rename-file-and-buffer)
+  (global-set-key (kbd "C-c o") 'crux-open-with))
 
+

Credits

@@ -2665,7 +2721,7 @@ along with this program. If not, see <
diff --git a/emacs/init.org b/emacs/init.org index 5632fa3..4444da9 100644 --- a/emacs/init.org +++ b/emacs/init.org @@ -200,6 +200,24 @@ I've hacked my own theme called [[https://github.com/mssola/soria][soria]]. This (load-theme 'soria t) #+END_SRC +When hacking your own theme, sometimes you want to know what face is the one +that you see on the screen right now. This function from [[https://github.com/thblt/DotFiles][@thblt]] allows me to +get exactly that: + +#+BEGIN_SRC elisp +(defun mssola-face-at-point (pos) + "Writes a message with the name of the face at the current point. The POS + argument contains the current position of the cursor." + + (interactive "d") + + (let ((face (or (get-char-property (point) 'read-face-name) + (get-char-property (point) 'face)))) + (if face (message "Face: %s" face) (message "No face at %d" pos)))) + +(global-set-key (kbd "C-c f") 'mssola-face-at-point) +#+END_SRC + ** General global key bindings Use kill-this-buffer instead of kill-buffer. @@ -440,9 +458,7 @@ Then, for keeping up with my projects I use the Projectile + Helm combination. (use-package projectile :ensure t :config - (projectile-mode 1) - (setq projectile-mode-line - '(:eval (format " %s" (projectile-project-name))))) + (projectile-mode 1)) (use-package helm :ensure t @@ -922,37 +938,54 @@ A git porcelain for GNU Emacs. Even if I'm still using the git CLI, it's certainly useful for some common tasks (I guess that I still need some learning). #+BEGIN_SRC elisp - (use-package magit - :ensure t - :config +(use-package magit + :ensure t + :config +#+END_SRC - ; Proper initial states. - (with-eval-after-load 'evil - (add-hook 'git-commit-mode-hook 'evil-insert-state) - (evil-set-initial-state 'magit-log-edit-mode 'insert)) +In some cases normal mode is not the right mode (e.g. commit mode). For these +cases, set the proper default mode. + +#+BEGIN_SRC elisp + (with-eval-after-load 'evil + (add-hook 'git-commit-mode-hook 'evil-insert-state) + (evil-set-initial-state 'magit-log-edit-mode 'insert)) +#+END_SRC - ; When showing the status, hide the usually-redundant "branch" section and - ; show the rest. - (add-hook 'magit-section-set-visibility-hook - '(lambda (section) - (if (string= (magit-section-type section) "branch") - 'hide - 'show))) +When showing the status, hide the usually-redundant "branch" section and show +the rest. - (with-eval-after-load 'evil-leader - (evil-leader/set-key "s" 'magit-status) +#+BEGIN_SRC elisp + (add-hook 'magit-section-set-visibility-hook + '(lambda (section) + (if (string= (magit-section-type section) "branch") + 'hide + 'show))) +#+END_SRC - (use-package evil-magit - :ensure t - :config +Set a key binding for =magit-blame=. - ; The magit + evil-magit combo messes up some chords, let's fix this. - (evil-define-key 'normal magit-mode-map - "\C-h" 'evil-window-left - "\C-l" 'evil-window-right - "\C-j" 'evil-window-down - "\C-k" 'evil-window-up - "\M-p" 'helm-projectile-switch-project)))) +#+BEGIN_SRC elisp + (global-set-key (kbd "C-c b") 'magit-blame) +#+END_SRC + +And repair some key bindings from Evil mode. + +#+BEGIN_SRC elisp + (with-eval-after-load 'evil-leader + (evil-leader/set-key "s" 'magit-status) + + (use-package evil-magit + :ensure t + :config + + ; The magit + evil-magit combo messes up some chords, let's fix this. + (evil-define-key 'normal magit-mode-map + "\C-h" 'evil-window-left + "\C-l" 'evil-window-right + "\C-j" 'evil-window-down + "\C-k" 'evil-window-up + "\M-p" 'helm-projectile-switch-project)))) #+END_SRC * mu4e @@ -1875,12 +1908,15 @@ Emacs style instead of being more Vim-like on purpose (I don't want to put too many things into my leader and these shortcuts look sensible to me). #+BEGIN_SRC elisp - (use-package crux - :ensure t - :bind (("C-c d" . crux-delete-file-and-buffer) - ("C-c r" . crux-rename-file-and-buffer) - ("C-c o" . crux-open-with))) +(use-package crux + :ensure t + :config + + (global-set-key (kbd "C-c d") 'crux-delete-file-and-buffer) + (global-set-key (kbd "C-c r") 'crux-rename-file-and-buffer) + (global-set-key (kbd "C-c o") 'crux-open-with)) #+END_SRC + * Credits I've built this file by simply scavenging from other people's emacs.d/dotfiles -- cgit v1.2.3