From a546b0b45b0e27ecfccb25393db439a03c71d16c Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Thu, 3 Nov 2022 08:22:25 -0400 Subject: Better new file and rename functionality --- README.md | 1 + lisp/general.el | 34 +++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 5750423..1831351 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Emacs configuration file - Grep in project: `s-F` - Refactor : `F2` - Move line up/down: `M-` +- Find references: `M-?` ## Per-language Features 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 -- cgit v1.2.1