1
任何人都可以引導我正確地使用gist.el
編輯現有Gist的文件名。我試過修改gist-edit-current-description
來處理文件名修改,但我嘗試的變化沒有奏效。這裏是gist-edit-current-description
功能 - 我想編輯的文件名會類似於描述的東西:如何用Emacs中的`gist.el`編輯Gist文件名
(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))))))
這可能有助於給別人的一些想法 - 這是在時間設置文件名的方法吉斯特創作的(它是基於@Jordon比翁預先回答 - https://stackoverflow.com/a/22973794/2112489):
(defun gist-region-with-filename-description (begin end &optional filename 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 (if filename filename (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)))
(defun gist-buffer-with-filename-description (&optional filename description private)
"Post the current buffer as a new paste at gist.github.com.
Copies the URL into the kill ring.
With a prefix argument, makes a private paste."
(interactive "P")
(let* (
(filename (if filename filename (read-string "Filename: " (buffer-name))))
(description (if description description (read-string "Description: " (buffer-name)))))
(gist-region-with-filename-description (point-min) (point-max) filename description private nil)))
您應該停止盲目猜測,而是閱讀[API文檔](https://developer.github.com/v3/gists/#edit-a-gist)... – lunaryorn
這並不容易完成目前的gist.el. api需要發送一些json,比如「oldfilename:{filename:newfilename}」,但是gist.el總是爲舊的和新的都使用一個文件名。這將需要一些更好的改造。可能會爲一個好項目做出貢獻。除了包含文件列表的gh-gist-gist對象外,它們應該有一個以文件名爲關鍵字的gh-gist-gist-file對象的散列。所以你可以做gist.files [文件名] .filename = newname(但是在lisp中) –
看看函數'gh-gist-gist-file-to-obj',你會看到問題 –