Gist (gist.el / Emacs) - set "description" at creation time

The gist-regiondefault behavior is to leave the description empty. To set a description, you must go to the buffer gist-list, and then use the function gist-edit-current-descriptionto set the description .

I would like to be able to set the description at the same time that gist is created, without going to the buffer gist-list. The default mini-buffer prompt buffer-namewill be the preferred method of processing it. How can this be done programmatically?

Here are two main functions in gist.elthat 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))))))
+4
1

gist-internal-new, gist-region.

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

- , gist-region nil. gist-region, ,

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

, ! , , .

, interactive, , args gists.

, `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)))
+4

Source: https://habr.com/ru/post/1535803/


All Articles