mirror of
https://github.com/correl/dotfiles.git
synced 2024-11-16 19:19:28 +00:00
32 lines
1.2 KiB
EmacsLisp
32 lines
1.2 KiB
EmacsLisp
;; emacsredux.com
|
|
(defun rename-file-and-buffer ()
|
|
"Rename the current buffer and file it is visiting."
|
|
(interactive)
|
|
(let ((filename (buffer-file-name)))
|
|
(if (not (and filename (file-exists-p filename)))
|
|
(message "Buffer is not visiting a file!")
|
|
(let ((new-name (read-file-name "New name: " filename)))
|
|
(cond
|
|
((vc-backend filename) (vc-rename-file filename new-name))
|
|
(t
|
|
(rename-file filename new-name t)
|
|
(rename-buffer new-name)
|
|
(set-visited-file-name new-name)
|
|
(set-buffer-modified-p nil)))))))
|
|
|
|
(defadvice ido-find-file (after find-file-sudo activate)
|
|
"Find file as root if necessary."
|
|
(unless (and buffer-file-name
|
|
(file-writable-p buffer-file-name))
|
|
(find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
|
|
|
|
(defun eval-and-replace ()
|
|
"Replace the preceding sexp with its value."
|
|
(interactive)
|
|
(backward-kill-sexp)
|
|
(condition-case nil
|
|
(prin1 (eval (read (current-kill 0)))
|
|
(current-buffer))
|
|
(error (message "Invalid expression")
|
|
(insert (current-kill 0)))))
|
|
(global-set-key (kbd "C-)") 'eval-and-replace)
|