[spacemacs-defaults] Move new function to correct file

This commit is contained in:
Maximilian Wolff 2021-05-04 21:58:43 +02:00
parent 4fc78bdc02
commit 1169eb3709
No known key found for this signature in database
GPG Key ID: 2DD07025BFDBD89A
3 changed files with 22 additions and 3 deletions

View File

@ -2521,6 +2521,7 @@ File manipulation commands (start with ~f~):
| Key binding | Description |
|-------------+--------------------------------------------------------------------------------------------------------|
| ~SPC f A~ | open a file and replace the current buffer with the new file |
| ~SPC f a~ | open a file and open it in a new buffer leaving the old buffer untouched |
| ~SPC f b~ | go to file bookmarks |
| ~SPC f c~ | copy current file to a different location |
| ~SPC f C d~ | convert file from unix to dos encoding |

View File

@ -510,6 +510,24 @@ initialized with the current directory instead of filename."
(spacemacs/rename-buffer-visiting-a-file arg)
(spacemacs/rename-buffer-or-save-new-file))))
(defun spacemacs/save-file-as-and-open (filename)
"Save current buffer into file FILENAME and open it in a new buffer."
(interactive
(list (if buffer-file-name
(read-file-name "Save file as and open: " buffer-file-name)
(read-file-name "Save file as and open: " default-directory))))
(or (null filename) (string-equal filename "")
(progn
(let ((dir (file-name-directory filename)))
(when (and (not (file-exists-p dir))
(yes-or-no-p (format "Create directory '%s'?" dir)))
(make-directory dir t)))
(and (file-exists-p filename)
(or (y-or-n-p (format "File `%s' exists; overwrite? " filename))
(error "Canceled")))
(write-region (point-min) (point-max) filename)
(find-file filename))))
(defun spacemacs/show-hide-helm-or-ivy-prompt-msg (msg sec)
"Show a MSG at the helm or ivy prompt for SEC.
With Helm, remember the path, then restore it after SEC.

View File

@ -361,7 +361,7 @@
:global
(("f" "Files"
("A" spacemacs/find-file-and-replace-buffer "Set another file for buffer...")
("a" spacemacs/save-file-as-and-open "Save current buffer and open in new buffer...")
("a" spacemacs/save-file-as-and-open "Copy file to new: file and buffer...")
("c" spacemacs/copy-file "Copy file to new file...")
("D" spacemacs/delete-current-buffer-file "Delete...")
("i" spacemacs/insert-file "Insert file content...")
@ -389,8 +389,8 @@
("v" "Variables"
("d" add-dir-local-variable "Add directory-local variable...")
("f" add-file-local-variable "Add bottom file variable...")
("p" add-file-local-variable-prop-line "Add top file property...")
)
("p" add-file-local-variable-prop-line "Add top file property..."))
("y" "Yank/Copy"
("c" spacemacs/copy-file-path-with-line-column "File path with line and column")
("d" spacemacs/copy-directory-path "Directory path")