首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从dired模式创建新文件?

如何从dired模式创建新文件?
EN

Stack Overflow用户
提问于 2013-11-30 20:18:39
回答 6查看 30.7K关注 0票数 58

我想在dired模式下创建一个新文件。在dired模式下有"create new file“命令吗?例如,当我在dired模式下输入"c“时,它会创建"untitled.txt”。很简单,但是我找不到。

EN

回答 6

Stack Overflow用户

发布于 2013-11-30 20:22:40

只要按C-x C-f就行了。这将提示输入文件名,并使用当前缓冲区的当前目录作为放置该文件的目录。对于dired buffer,它的当前目录就是您正在查看的目录。

票数 59
EN

Stack Overflow用户

发布于 2013-12-01 01:28:07

如果您想让处于Dired模式的c执行C-x C-f所做的事情,那么答案就是简单的

代码语言:javascript
复制
(define-key dired-mode-map "c" 'find-file)

或者,如果您希望它的名称为untitled.txt,那么:

代码语言:javascript
复制
(define-key dired-mode-map "c"
  (lambda () (interactive) (find-file "untitled.txt")))
票数 29
EN

Stack Overflow用户

发布于 2013-12-01 16:24:22

多亏了所有人,我终于自己解决了,。Here是我的答案。在dired模式下键入"c“将提示您创建新的无标题文件。然后按enter将创建新的无标题文件。是的,这是非常冗长的代码。也许有人会修好它。

代码语言:javascript
复制
(eval-after-load 'dired
  '(progn
     (define-key dired-mode-map (kbd "c") 'my-dired-create-file)
     (defun create-new-file (file-list)
       (defun exsitp-untitled-x (file-list cnt)
         (while (and (car file-list) (not (string= (car file-list) (concat "untitled" (number-to-string cnt) ".txt"))))
           (setq file-list (cdr file-list)))
         (car file-list))

       (defun exsitp-untitled (file-list)
         (while (and (car file-list) (not (string= (car file-list) "untitled.txt")))
           (setq file-list (cdr file-list)))
         (car file-list))

       (if (not (exsitp-untitled file-list))
           "untitled.txt"
         (let ((cnt 2))
           (while (exsitp-untitled-x file-list cnt)
             (setq cnt (1+ cnt)))
           (concat "untitled" (number-to-string cnt) ".txt")
           )
         )
       )
     (defun my-dired-create-file (file)
       (interactive
        (list (read-file-name "Create file: " (concat (dired-current-directory) (create-new-file (directory-files (dired-current-directory))))))
        )
       (write-region "" nil (expand-file-name file) t) 
       (dired-add-file file)
       (revert-buffer)
       (dired-goto-file (expand-file-name file))
       )
     )
  )
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20300137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档