From c13a1df74e0160ff62eb8c54fb4104ec8b93aa36 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 3 Jan 2013 18:14:05 -0500 Subject: rename file func and separate util.el moved whitespace cleanup here --- conf/em.el | 8 -------- conf/util.el | 29 +++++++++++++++++++++++++++++ init.el | 1 + 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 conf/util.el 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") -- cgit v1.2.3