summary refs log tree commit diff
path: root/emacs.d/lib/my-functions.el
diff options
context:
space:
mode:
authorFranck Cuny <franckcuny@gmail.com>2016-08-04 09:29:08 -0700
committerFranck Cuny <franckcuny@gmail.com>2016-08-04 09:30:12 -0700
commit556a4734f46d0538e7709708f84eb7a0a16ea9b0 (patch)
tree30ebbea1b682e497a1811ae248a55bc5b23bd80b /emacs.d/lib/my-functions.el
parentConvert README from markdown to org-mode. (diff)
downloademacs.d-556a4734f46d0538e7709708f84eb7a0a16ea9b0.tar.gz
[emacs] Move back to `use-package'.
Move some settings out from 'init.el' to make it easier to read.

Closes #18, closes #17, closes #7.
Diffstat (limited to '')
-rw-r--r--emacs.d/lib/my-functions.el38
1 files changed, 38 insertions, 0 deletions
diff --git a/emacs.d/lib/my-functions.el b/emacs.d/lib/my-functions.el
new file mode 100644
index 0000000..e661a01
--- /dev/null
+++ b/emacs.d/lib/my-functions.el
@@ -0,0 +1,38 @@
+;; jump to the scratch buffer
+(defun fc/switch-to-scratch ()
+  "Switch to scratch, grab the region if it's active."
+  (interactive)
+  (let ((contents
+         (and (region-active-p)
+              (buffer-substring (region-beginning)
+                                (region-end)))))
+    (switch-to-buffer "*scratch*")
+    (if contents
+        (progn
+          (goto-char (buffer-end 1))
+          (insert contents)))))
+
+(global-set-key (kbd "s-N") 'fc/switch-to-scratch)
+
+;; rename a buffer
+(defun fc/rename-this-buffer-and-file ()
+  "Renames current buffer and file it is visiting."
+  (interactive)
+  (let ((name (buffer-name))
+        (filename (buffer-file-name))
+        (read-file-name-function 'read-file-name-default))
+    (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)))
+        (cond ((get-buffer new-name)
+               (error "A buffer named '%s' already exists!" new-name))
+              (t
+               (rename-file filename new-name 1)
+               (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))))))))
+
+
+
+(provide 'my-functions)