From 8adfee8fc3c84e2dd40d2d43c4ed91160eace5ff Mon Sep 17 00:00:00 2001 From: Peng Li Date: Sun, 6 Nov 2016 12:27:16 +0800 Subject: [PATCH] emacs - add dired create file --- emacs.d/config.org | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/emacs.d/config.org b/emacs.d/config.org index 127173d..fb67ad2 100644 --- a/emacs.d/config.org +++ b/emacs.d/config.org @@ -1749,11 +1749,24 @@ as a http download client tool #+END_SRC #+BEGIN_SRC emacs-lisp :tangle yes :results silent - (defun sd/dired-new-file () + (defun sd/dired-new-file-and-open () "Create a new file in dired mode" (interactive) (call-interactively 'find-file)) + (defun sd/dired-new-file (file) + "Create a new file called FILE. + If FILE already exists, signal an error." + (interactive + (list (read-file-name "Create file: " (dired-current-directory)))) + (let* ((expanded (expand-file-name file))) + (if (file-exists-p expanded) + (error "Cannot create file %s: file exists" expanded)) + (write-region "" nil expanded t) + (when expanded + (dired-add-file expanded) + (dired-move-to-filename)))) + ;; copied from abo-abo's config (defun sd/dired-get-size () (interactive) @@ -1803,6 +1816,7 @@ Disalble =ido= when new a directory or file in =dired= mode #+BEGIN_SRC emacs-lisp :tangle yes :results silent ;; call the function which you want to disable ido (mk-disable-ido 'dired-create-directory) + (mk-disable-ido 'sd/dired-new-file-and-open) (mk-disable-ido 'sd/dired-new-file) (mk-disable-ido-no-completing 'dired-goto-file) #+END_SRC -- 2.11.0