summaryrefslogtreecommitdiff
path: root/conf
diff options
context:
space:
mode:
authorKyle Meyer <meyerkya@gmail.com>2013-01-03 18:14:05 -0500
committerKyle Meyer <meyerkya@gmail.com>2013-01-04 15:55:28 -0500
commitc13a1df74e0160ff62eb8c54fb4104ec8b93aa36 (patch)
tree9d73086d63baf4b7a663032b593cedddaad3293d /conf
parent404c901c3ad85458e4ec171782a1b5020d3f04bb (diff)
downloademacs.d-c13a1df74e0160ff62eb8c54fb4104ec8b93aa36.tar.gz
rename file func and separate util.el
moved whitespace cleanup here
Diffstat (limited to 'conf')
-rw-r--r--conf/em.el8
-rw-r--r--conf/util.el29
2 files changed, 29 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)