summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorMatthew Kosarek <mattkae@protonmail.com>2022-11-03 08:22:25 -0400
committerMatthew Kosarek <mattkae@protonmail.com>2022-11-03 08:22:25 -0400
commita546b0b45b0e27ecfccb25393db439a03c71d16c (patch)
tree2d728929b761f419de3b7f58cb85f77bcdc6a7d1 /lisp
parentc355971b0ae82eb22b57820547dee5afba3203a2 (diff)
Better new file and rename functionality
Diffstat (limited to 'lisp')
-rw-r--r--lisp/general.el34
1 files changed, 23 insertions, 11 deletions
diff --git a/lisp/general.el b/lisp/general.el
index 6def4b8..68e3521 100644
--- a/lisp/general.el
+++ b/lisp/general.el
@@ -141,10 +141,11 @@
(bind-key* (kbd "M-x") 'counsel-M-x)
(bind-key* (kbd "C-;") 'neotree-toggle)
-(defun my-create-file ()
- "Create a file and refresh neotree."
- (interactive)
- (call-interactively #'make-empty-file)
+(defun my-create-file (filename)
+ "Create a file and refresh neotree. FILENAME File to create."
+ (interactive (list (read-file-name "Enter your file name: " nil nil nil (file-name-nondirectory ""))))
+ (make-empty-file filename)
+ (find-file filename)
(neotree-show)
(neotree-refresh)
(other-window -1))
@@ -178,13 +179,24 @@
(other-window -1))
(bind-key* (kbd "M-D") 'my-delete-directory)
-(defun my-rename-file ()
- "Rename a file and refresh neotree."
- (interactive)
- (call-interactively #'rename-file)
- (neotree-show)
- (neotree-refresh)
- (other-window -1))
+;; source: http://steve.yegge.googlepages.com/my-dot-emacs-file
+(defun my-rename-file (new-name)
+ "Renames both current buffer and file it's visiting to NEW-NAME."
+ (interactive "sNew name: ")
+ (let ((name (buffer-name))
+ (filename (buffer-file-name)))
+ (if (not filename)
+ (message "Buffer '%s' is not visiting a file!" name)
+ (if (get-buffer new-name)
+ (message "A buffer named '%s' already exists!" new-name)
+ (progn
+ (rename-file filename new-name 1)
+ (rename-buffer new-name)
+ (set-visited-file-name new-name)
+ (set-buffer-modified-p nil)
+ (neotree-show)
+ (neotree-refresh)
+ (other-window -1))))))
(bind-key* (kbd "M-r") 'my-rename-file)
;; Company mode for code completion