diff options
Diffstat (limited to 'conf')
-rw-r--r-- | conf/em.el | 8 | ||||
-rw-r--r-- | conf/util.el | 29 |
2 files changed, 29 insertions, 8 deletions
@@ -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) |