Fix some bugs in python linting on devserver
This commit is contained in:
parent
2d92526d24
commit
de8429de5d
5 changed files with 155 additions and 51 deletions
128
.emacs.d/quip.el
128
.emacs.d/quip.el
|
|
@ -1,19 +1,33 @@
|
|||
;; Quip API
|
||||
;;; quip.el --- Quip API client for emacs -*- lexical-binding: t; -*-
|
||||
;;; Commentary:
|
||||
|
||||
(require 'cl-extra)
|
||||
;;; Code:
|
||||
|
||||
(require 'cl-lib)
|
||||
(require 'json)
|
||||
(require 'url)
|
||||
|
||||
|
||||
;; Customization groups
|
||||
(defgroup quip-api nil
|
||||
"Customization options for using the Quip API")
|
||||
"Customization options for using the Quip API"
|
||||
:prefix "quip-"
|
||||
:group 'external
|
||||
:tag "Quip")
|
||||
|
||||
(defcustom quip-api-key nil
|
||||
"Your API key for Quip. Get it from https://fb.quip.com/api/personal-token"
|
||||
:type 'string)
|
||||
(defcustom quip-api-key ""
|
||||
"Your API key for Quip.
|
||||
|
||||
Get it from https://fb.quip.com/api/personal-token."
|
||||
:type 'string
|
||||
:group 'quip-api)
|
||||
|
||||
(defun quip-invoke-json (path method params)
|
||||
"Submit a request to the Quip API. Returns the parsed JSON from the response."
|
||||
"Make a request to the Quip API, and return the parsed JSON from the response.
|
||||
|
||||
A Quip API call involves issuing an HTTP request to path PATH,
|
||||
with method METHOD, and parameters PARAMS. This routine knows the
|
||||
base URL and adds the necessary headers."
|
||||
(if (not quip-api-key)
|
||||
(error "%s"
|
||||
"The custom variable quip-api-key is undefined. Use custom-set-variable to set it before using quip."))
|
||||
|
|
@ -32,14 +46,18 @@
|
|||
(json-read))))
|
||||
|
||||
(defun quip-new-document (content &optional format)
|
||||
"Create a new Quip document with the provided content. Returns the parsed JSON response."
|
||||
"Create a new Quip document with the provided CONTENT.
|
||||
|
||||
This function returns the parsed JSON response. The optional
|
||||
FORMAT argument is one of 'html' or 'markdown', and indicates
|
||||
that the content should be interpreted as such."
|
||||
(quip-invoke-json "threads/new-document"
|
||||
"POST"
|
||||
`((format . ,(or format "markdown"))
|
||||
(content . ,content))))
|
||||
|
||||
(defun quip-get-thread (id)
|
||||
"Get the Quip thread with the specified ID. Returns the parsed JSON response."
|
||||
"Get the Quip thread with the specified ID. Return the parsed JSON response."
|
||||
(quip-invoke-json (concat "threads/" id) "GET" nil))
|
||||
|
||||
(defconst quip-location-append 0)
|
||||
|
|
@ -50,7 +68,11 @@
|
|||
(defconst quip-location-delete-section 5)
|
||||
|
||||
(defun quip-thread-append (thread content &optional format)
|
||||
"Append the content to the specified thread."
|
||||
; checkdoc-order: nil
|
||||
"Append CONTENT to the specified THREAD.
|
||||
|
||||
The optional FORMAT argument is one of 'html' or 'markdown', and
|
||||
indicates how the content is to be interpreted."
|
||||
(quip-invoke-json "threads/edit-document"
|
||||
"POST"
|
||||
`((format . ,(or format "markdown"))
|
||||
|
|
@ -59,7 +81,11 @@
|
|||
(thread_id . ,thread))))
|
||||
|
||||
(defun quip-thread-prepend (thread content &optional format)
|
||||
"Prepend the content to the specified thread."
|
||||
; checkdoc-order: nil
|
||||
"Prepend CONTENT to the specified THREAD.
|
||||
|
||||
The optional FORMAT argument is one of 'html' or 'markdown', and
|
||||
indicates how the content is to be interpreted."
|
||||
(quip-invoke-json "threads/edit-document"
|
||||
"POST"
|
||||
`((format . ,(or format "markdown"))
|
||||
|
|
@ -68,27 +94,43 @@
|
|||
(thread_id . ,thread))))
|
||||
|
||||
(defun quip-thread-append-after (thread section content &optional format)
|
||||
"Append the content to the specified thread after the specified section."
|
||||
; checkdoc-order: nil
|
||||
"Append CONTENT to specified SECTION in the specified THREAD.
|
||||
|
||||
The content is appended after the specified section.
|
||||
|
||||
The optional FORMAT argument is one of 'html' or 'markdown', and
|
||||
indicates how the content is to be interpreted."
|
||||
(quip-invoke-json "threads/edit-document"
|
||||
"POST"
|
||||
`((format . ,(or format "markdown"))
|
||||
(content . ,content)
|
||||
(location . ,quip-location-append-section)
|
||||
(location . ,quip-location-after-section)
|
||||
(section_id . ,section)
|
||||
(thread_id . ,thread))))
|
||||
|
||||
(defun quip-thread-prepend-before (thread section content &optional format)
|
||||
"Prepend the content to the specified thread before the specified section."
|
||||
; checkdoc-order: nil
|
||||
"Prepend CONTENT to the specified SECTION of THREAD.
|
||||
|
||||
The content is added before the specified section.
|
||||
|
||||
The optional FORMAT argument is one of 'html' or 'markdown', and
|
||||
indicates how the content is to be interpreted."
|
||||
(quip-invoke-json "threads/edit-document"
|
||||
"POST"
|
||||
`((format . ,(or format "markdown"))
|
||||
(content . ,content)
|
||||
(location . ,quip-location-prepend-section)
|
||||
(location . ,quip-location-before-section)
|
||||
(section_id . ,section)
|
||||
(thread_id . ,thread))))
|
||||
|
||||
(defun quip-thread-replace-section (thread section content &optional format)
|
||||
"Replace the content of the specified section."
|
||||
; checkdoc-order: nil
|
||||
"Replace the specified SECTION of THREAD with the specified CONTENT.
|
||||
|
||||
The optional FORMAT argument is one of 'html' or 'markdown', and
|
||||
indicates how the content is to be interpreted."
|
||||
(quip-invoke-json "threads/edit-document"
|
||||
"POST"
|
||||
`((format . ,(or format "markdown"))
|
||||
|
|
@ -97,13 +139,12 @@
|
|||
(section_id . ,section)
|
||||
(thread_id . ,thread))))
|
||||
|
||||
(defun quip-thread-delete-section (thread section &optional format)
|
||||
"Delete the specified section."
|
||||
(defun quip-thread-delete-section (thread section)
|
||||
; checkdoc-order: nil
|
||||
"Delete the specified SECTION of THREAD."
|
||||
(quip-invoke-json "threads/edit-document"
|
||||
"POST"
|
||||
`((format . ,(or format "markdown"))
|
||||
(content . ,content)
|
||||
(location . ,quip-location-delete-section)
|
||||
`((location . ,quip-location-delete-section)
|
||||
(section_id . ,section)
|
||||
(thread_id . ,thread))))
|
||||
|
||||
|
|
@ -111,8 +152,8 @@
|
|||
;;; Content parsing functions
|
||||
|
||||
(defun quip-get-item-type (item)
|
||||
(let ((elem-type (car item))
|
||||
(attribs (cadr item)))
|
||||
"Classify the specified HTML ITEM."
|
||||
(let ((elem-type (car item)))
|
||||
(cond
|
||||
((eq elem-type 'p) 'paragraph)
|
||||
((eq elem-type 'h1) 'h1)
|
||||
|
|
@ -124,8 +165,7 @@
|
|||
((eq elem-type 'li) 'list-item)
|
||||
((eq elem-type 'span) 'span)
|
||||
((eq elem-type 'div)
|
||||
(letrec ((style (assoc-default 'data-section-style attribs))
|
||||
(inner (caddr item))
|
||||
(letrec ((inner (cl-caddr item))
|
||||
(inner-elem-type (car inner)))
|
||||
(cond
|
||||
((eq inner-elem-type 'ul) 'ul)
|
||||
|
|
@ -133,40 +173,49 @@
|
|||
(t 'unrecognized-inner))))
|
||||
(t 'unrecognized))))
|
||||
|
||||
(defun quip-get-item-id (type item)
|
||||
(defun quip-get-item-id (item type)
|
||||
"Extract the ID from the provided ITEM given its TYPE."
|
||||
(let ((attribs (cadr item)))
|
||||
(cond
|
||||
((or (eq type 'ul) ;; Nested IDs.
|
||||
(eq type 'ol))
|
||||
(letrec ((inner (caddr item))
|
||||
(letrec ((inner (cl-caddr item))
|
||||
(inner-attribs (cadr inner)))
|
||||
(assoc-default 'id inner-attribs)))
|
||||
(t (assoc-default 'id attribs)))))
|
||||
|
||||
(defun quip-get-item-content (type item)
|
||||
(defun quip-get-item-content (item type)
|
||||
"Extract the content from the provided ITEM given its TYPE."
|
||||
(cond
|
||||
((or (eq type 'ul) ;; Nested Content
|
||||
(eq type 'ol))
|
||||
(letrec ((inner (caddr item))
|
||||
(letrec ((inner (cl-caddr item))
|
||||
(inner-elems (cddr inner)))
|
||||
(mapcar #'quip-get-item-from-element inner-elems)))
|
||||
(t (caddr item))))
|
||||
(t (cl-caddr item))))
|
||||
|
||||
(cl-defstruct quip-item type id content)
|
||||
|
||||
(defun quip-get-item-from-element (element)
|
||||
"Construct a (type, id, content) list from the given ELEMENT."
|
||||
(letrec
|
||||
((item-type (quip-get-item-type element))
|
||||
(item-id (quip-get-item-id item-type element))
|
||||
(item-content (quip-get-item-content item-type element)))
|
||||
`(,item-type ,item-id ,item-content)))
|
||||
(item-id (quip-get-item-id element item-type))
|
||||
(item-content (quip-get-item-content element item-type)))
|
||||
(make-quip-item
|
||||
:type item-type
|
||||
:id item-id
|
||||
:content item-content)))
|
||||
|
||||
|
||||
(defun quip-parse-html-content (content)
|
||||
(defun quip-parse-html-content (html)
|
||||
"Parse the provided HTML into a list of (type, item, content) lists."
|
||||
(with-temp-buffer
|
||||
(insert content)
|
||||
(insert html)
|
||||
(letrec
|
||||
((html (libxml-parse-html-region (point-min) (point-max)))
|
||||
(raw-items (cddr (caddr html)))
|
||||
(html-items (remove-if #'stringp raw-items)))
|
||||
((parsed-html (libxml-parse-html-region (point-min) (point-max)))
|
||||
(raw-items (cddr (cl-caddr parsed-html)))
|
||||
(html-items (cl-remove-if #'stringp raw-items)))
|
||||
|
||||
(mapcar #'quip-get-item-from-element html-items)
|
||||
)))
|
||||
|
|
@ -175,4 +224,5 @@
|
|||
;; (quip-parse-html-content
|
||||
;; (assoc-default 'html (quip-get-thread "idflAWG6R6Uu"))))
|
||||
|
||||
(provide 'quip-api)
|
||||
(provide 'quip)
|
||||
;;; quip.el ends here
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue