summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2016-10-11 21:03:46 +0200
committerAlan Pearce2016-10-11 21:03:46 +0200
commit9f5adf96d04f246e4f6a081aba2c53c1c8eb47f1 (patch)
treeae848b8264a0b28fd2872916de031fe100e4537e
parent77e71f8020c4dcbe29b0d1c7425e1ae5faa2a6a0 (diff)
downloaddotfiles-9f5adf96d04f246e4f6a081aba2c53c1c8eb47f1.tar.lz
dotfiles-9f5adf96d04f246e4f6a081aba2c53c1c8eb47f1.tar.zst
dotfiles-9f5adf96d04f246e4f6a081aba2c53c1c8eb47f1.zip
Emacs: Replace simple functions with crux.el
-rw-r--r--tag-emacs/emacs.d/init.org70
1 files changed, 22 insertions, 48 deletions
diff --git a/tag-emacs/emacs.d/init.org b/tag-emacs/emacs.d/init.org
index 405ef13..b1c69e7 100644
--- a/tag-emacs/emacs.d/init.org
+++ b/tag-emacs/emacs.d/init.org
@@ -306,6 +306,28 @@ Option/alt, then Control.
   (bind-key* "C-M-x" #'execute-extended-command)
   (set-register ?z `(file . ,(expand-file-name ".config/zsh/zshrc" "~")))
 #+END_SRC
+
+** Crux
+
+I can replace most of the simple helper/wrapper functions in my
+configuration with crux.el
+
+#+BEGIN_SRC emacs-lisp
+  (use-package crux
+	:bind (("C-o" . crux-smart-open-line-above)
+		   ("M-o" . crux-smart-open-line)
+
+		   ("C-x 4 t" . crux-transpose-windows)
+		   ("C-c e" . crux-eval-and-replace)
+		   ("C-c D" . crux-delete-file-and-buffer)
+		   ("C-c R" . crux-rename-file-and-buffer))
+	:init (progn
+			(defalias 'delete-current-buffer-file #'crux-delete-file-and-buffer)
+			(defalias 'rename-current-buffer-file #'crux-rename-file-and-buffer)))
+
+
+#+END_SRC
+
 * Projects
 
    #+BEGIN_SRC emacs-lisp
@@ -516,36 +538,6 @@ I often want to rename or delete the file that I’m currently visiting
 with a buffer.
 
 #+BEGIN_SRC emacs-lisp
-  (defun rename-current-buffer-file ()
-	"Renames current buffer and file it is visiting."
-	(interactive)
-	(let ((name (buffer-name))
-		  (filename (buffer-file-name)))
-	  (if (not (and filename (file-exists-p filename)))
-		  (error "Buffer '%s' is not visiting a file!" name)
-		(let ((new-name (read-file-name "New name: " filename)))
-		  (if (get-buffer new-name)
-			  (error "A buffer named '%s' already exists!" new-name)
-			(cond
-			 ((vc-backend filename) (vc-rename-file filename new-name))
-			 (t (rename-file filename new-name t)
-				(rename-buffer new-name)
-				(set-visited-file-name new-name)
-				(set-buffer-modified-p nil)
-				(message "File '%s' successfully renamed to '%s'"
-						 name (file-name-nondirectory new-name)))))))))
-
-  (defun delete-current-buffer-file ()
-	"Removes file connected to current buffer and kills buffer."
-	(interactive)
-	(let ((filename (buffer-file-name)))
-	  (if (not (and filename (file-exists-p filename)))
-		  (kill-this-buffer)
-		(when (yes-or-no-p "Are you sure you want to remove this file? ")
-		  (delete-file filename)
-		  (kill-this-buffer)
-		  (message "File '%s' successfully removed" filename)))))
-
   (defun kill-or-delete-this-buffer-dwim (&optional arg)
 	"Kills current buffer.  With prefix arg, delete it."
 	(interactive "P")
@@ -1704,24 +1696,6 @@ Interactive elisp
 										(run-hooks 'lisp-mode-common-hook)))))
 #+END_SRC
 
-I don’t only use this in elisp.  It’s nice to do calculations in other
-buffers too: it’s faster than quickrun and the parens mean that I
-don’t have to worry about a selection.
-
-#+BEGIN_SRC emacs-lisp
-(defun eval-and-replace ()
-  "Replace the preceding sexp with its value."
-  (interactive)
-  (backward-kill-sexp)
-  (condition-case nil
-	  (prin1 (eval (read (current-kill 0)))
-			 (current-buffer))
-	(error (message "Invalid expression")
-		   (insert (current-kill 0)))))
-
-(bind-key "C-c e" #'eval-and-replace)
-#+END_SRC
-
 *** Scheme & Lisp
 
 I don’t work with these as often as I would like