There is this function in tide:
;; Defined in ~/.emacs.d/.local/straight/repos/tide/tide.el
(defun tide-rename-file ()
"Rename current file and all it's references in other files."
(interactive)
(let* ((name (buffer-name))
(old (tide-buffer-file-name))
(basename (file-name-nondirectory old)))
(unless (and old (file-exists-p old))
(error "Buffer '%s' is not visiting a file." name))
(let ((new (read-file-name "New name: " (file-name-directory old) basename nil basename)))
(when (get-file-buffer new)
(error "A buffer named '%s' already exists." new))
(when (file-exists-p new)
(error "A file named '%s' already exists." new))
(let* ((old (expand-file-name old))
(new (expand-file-name new))
(response (tide-command:getEditsForFileRename old new)))
(tide-on-response-success response (:min-version "2.9")
(tide-do-rename-file old new (plist-get response :body))
(message "Renamed '%s' to '%s'." name (file-name-nondirectory new)))))))
It works well, but it works when called inside a buffer and with manual input of parameters.
I want to turn it into a function that I can call from elisp with the parameters sent through code instead of using the minibuffer through read-file-name
. Ideally something like
(defun tide-rename-file-MODIFIED (new old) .... )
I would like this to be a function with a new name e.g. tide-rename-file-MODIFIED
, so that I can still call tide-rename-file
as usual, from inside a buffer, with manual user input.
Perhaps I am better off writing my own function instead of trying to modify the existing function? I don't know.
Related Qs