summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conf/em.el8
-rw-r--r--conf/util.el29
-rw-r--r--init.el1
3 files changed, 30 insertions, 8 deletions
diff --git a/conf/em.el b/conf/em.el
index b919d85..6b5f12e 100644
--- a/conf/em.el
+++ b/conf/em.el
@@ -96,11 +96,3 @@
;; tramp
(require 'tramp)
(setq tramp-default-method "ssh")
-
-;; whitespace cleanup
-(defun cleanup-buffer ()
- (interactive)
- (untabify (point-min) (point-max))
- (delete-trailing-whitespace)
- (set-buffer-file-coding-system 'utf-8))
-(add-hook 'before-save-hook 'cleanup-buffer)
diff --git a/conf/util.el b/conf/util.el
new file mode 100644
index 0000000..bf9519d
--- /dev/null
+++ b/conf/util.el
@@ -0,0 +1,29 @@
+;; util.el -- utility functions
+
+;; http://whattheemacsd.com/
+;; whitespace cleanup
+(defun cleanup-buffer ()
+ (interactive)
+ (untabify (point-min) (point-max))
+ (delete-trailing-whitespace)
+ (set-buffer-file-coding-system 'utf-8))
+(add-hook 'before-save-hook 'cleanup-buffer)
+
+(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)
+ (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)))))))
+
+(global-set-key (kbd "C-x C-r") 'rename-current-buffer-file)
diff --git a/init.el b/init.el
index b13504e..13218fb 100644
--- a/init.el
+++ b/init.el
@@ -4,6 +4,7 @@
(add-to-list 'load-path "~/.emacs.d/conf")
(load "pkg.el")
(load "em.el")
+(load "util.el")
(load "ev.el")
(load "om.el")
(load "ibuf.el")