Gist(gist.el / Emacs) - 在创建时设置`description` [英] Gist (gist.el / Emacs) -- Set the `description` at the time of creation

查看:211
本文介绍了Gist(gist.el / Emacs) - 在创建时设置`description`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



以下是 gist.el 中的两个主要功能,负责上述行为:

 (defun gist-region(begin end& optional private callback)
将当前区域作为新的粘贴发布到gist.github.com
将URL复制到kill ring中

使用前缀参数进行私有粘贴。
(交互式r \\\
P)
(let *((file(或(buffer-file-name)(buffer-name)))
(name(file-name-nondirectory文件))
(ext(or(cdr(assoc major-mode gist-supported-modes-alist))
(文件扩展名文件)
txt))
(fname(concat(file-name-sans-extension name)。ext)
(files(list
(gh-gist-gist-filefile
: 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-minibufferDescription:old-descr)))
(let *((g(clone gist
:文件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))))))
pre>

解决方案

看看函数 gist-internal-new gist-region 正在调用。



(gist-internal-new FILES& optional PRIVATE DESCRIPTION CALLBACK)



第三个参数是描述,但 gist-region 将其设置为nil。您可以修改 gist-region 中的最后一个表达式,以从minibuffer中读取一个字符串来指定描述

 (gist-internal-new files private(read-from-minibufferGist Description:)回调)
pre>

或者更好的是,不要修改功能,只写自己的!这样,你不要混淆使用该功能的其他软件包。



这里只是一个稍微修改的版本,添加了一个额外的参数,并使用 interactive 可以自动提示用户进行说明,同时仍允许前缀参数设置私有图标。



与我们使用的第一个例子不同`read-from-minibuffer'这个将允许你使用代码中的函数,直接指定描述,而不强制提示被使用,除非它是交互式的。

  ;;请注意,我们添加了DESCRIPTION参数
(defun gist-region-with-description(begin end& optional description private callback)
将当前区域作为新的粘贴发布到gist.github.com
将URL复制到kill ring中

使用前缀参数进行私有粘贴。
(interactiver\\\
sGist说明:\\\
P);;我们在这里处理提示!
(let *((file(或(buffer-file-name)(buffer-name)))
(name(file-name-nondirectory file))
(ext(or(cdr(assoc major-mode gist-supported-modes-alist))
(文件扩展名文件)
txt))
(fname(concat (file-name-sans-extension name)。ext)
(files(list
(gh-gist-gist-filefile
:filename fname
:content(buffer-substring begin end)))))
;;最后我们使用我们的新arg来指定内部调用描述
(gist-internal-new file private description callback))


The default behavior of gist-region is to leave the description blank. To set the description, it is necessary to switch to the gist-list buffer and then use the function gist-edit-current-description to set the description.

I would like to be able to set the description at the same time that the gist is created, without switching to the gist-list buffer. A mini-buffer prompt that defaults to the buffer-name would be the preferred method of handling this. How can this be accomplished programmatically?

Here are the two main functions in gist.el that are responsible for the behavior described above:

(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))))))

解决方案

Take a look at the function gist-internal-new that gist-region is calling.

(gist-internal-new FILES &optional PRIVATE DESCRIPTION CALLBACK)

The third param is the description but gist-region is setting it to nil. You can modify that last expression in gist-region to read a string from the minibuffer to specify a description

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

Or better yet, don't modify the function and just write your own! That way, you don't mess with other packages that use the function.

Here is just a slightly a modified version that adds an extra parameter and uses interactive to automatically prompt the user for a description while still allowing prefix args to make private gists.

Unlike the first example when we used `read-from-minibuffer' this one will allow you to use the function in code and specify the description directly without forcing a prompt to be used unless it's called interactively.

;; 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)))

这篇关于Gist(gist.el / Emacs) - 在创建时设置`description`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆