默认行为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-new
that gist-region
正在呼叫。
(gist-internal-new FILES &optional PRIVATE DESCRIPTION CALLBACK)
第三个参数是描述,但是gist-region
正在将其设置为零。您可以修改最后一个表达式gist-region
从迷你缓冲区读取字符串以指定描述
(gist-internal-new files private (read-from-minibuffer "Gist Description: ") callback)
或者更好的是,不要修改函数,只需编写自己的函数!这样,您就不会弄乱使用该函数的其他包。
这只是一个稍微修改的版本,添加了一个额外的参数并使用interactive
自动提示用户输入描述,同时仍然允许前缀参数创建私有要点。
与我们使用“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)))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)