gpt4 book ai didi

emacs - Gist (gist.el/Emacs) -- 创建时设置 `description`

转载 作者:行者123 更新时间:2023-12-01 01:01:27 27 4
gpt4 key购买 nike

gist-region 的默认行为是离开描述 空白的。要设置描述,需要切换到gist-list缓冲然后使用函数gist-edit-current-description设置描述 .

我希望能够设置 描述 在创建要点的同时,无需切换到 gist-list缓冲。默认为 buffer-name 的小缓冲区提示将是处理此问题的首选方法。这如何以编程方式完成?

这是gist.el中的两个主要功能负责上述行为的人:

(defun gist-region (begin end &optional private callback)
"Post the current region as a new paste at gist.github.com
Copies the URL into the kill ring.

With a prefix argument, makes a private paste."
(interactive "r\nP")
(let* ((file (or (buffer-file-name) (buffer-name)))
(name (file-name-nondirectory file))
(ext (or (cdr (assoc major-mode gist-supported-modes-alist))
(file-name-extension file)
"txt"))
(fname (concat (file-name-sans-extension name) "." ext))
(files (list
(gh-gist-gist-file "file"
:filename fname
:content (buffer-substring begin end)))))
(gist-internal-new files private nil callback)))

(defun gist-edit-current-description ()
(interactive)
(let* ((id (tabulated-list-get-id))
(gist (gist-list-db-get-gist id))
(old-descr (oref gist :description))
(new-descr (read-from-minibuffer "Description: " old-descr)))
(let* ((g (clone gist
:files nil
:description new-descr))
(api (gist-get-api t))
(resp (gh-gist-edit api g)))
(gh-url-add-response-callback resp
(lambda (gist)
(gist-list-reload))))))

最佳答案

看看函数gist-internal-newgist-region正在打电话。
(gist-internal-new FILES &optional PRIVATE DESCRIPTION CALLBACK)
第三个参数是描述,但 gist-region将其设置为零。您可以在 gist-region 中修改最后一个表达式从 minibuffer 中读取字符串以指定描述

(gist-internal-new files private (read-from-minibuffer "Gist Description: ") callback)

或者更好的是,不要修改函数,只写你自己的!这样,您就不会弄乱使用该功能的其他包。

这里只是稍加修改的版本,增加了一个额外的参数并使用 interactive自动提示用户进行描述,同时仍然允许前缀 args 制作私有(private)要点。

与第一个示例不同,当我们使用 `read-from-minibuffer' 时,此示例将允许您在代码中使用该函数并直接指定描述,而无需强制使用提示,除非以交互方式调用它。

;; note that we added the DESCRIPTION argument
(defun gist-region-with-description (begin end &optional description private callback)
"Post the current region as a new paste at gist.github.com
Copies the URL into the kill ring.

With a prefix argument, makes a private paste."
(interactive "r\nsGist Description: \nP") ;; we handle the prompt here!
(let* ((file (or (buffer-file-name) (buffer-name)))
(name (file-name-nondirectory file))
(ext (or (cdr (assoc major-mode gist-supported-modes-alist))
(file-name-extension file)
"txt"))
(fname (concat (file-name-sans-extension name) "." ext))
(files (list
(gh-gist-gist-file "file"
:filename fname
:content (buffer-substring begin end)))))
;; finally we use our new arg to specify the description in the internal call
(gist-internal-new files private description callback)))

关于emacs - Gist (gist.el/Emacs) -- 创建时设置 `description`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22971635/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com