Skip to content

Instantly share code, notes, and snippets.

@xmaillard
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xmaillard/36e277e5cce310be2671 to your computer and use it in GitHub Desktop.
Save xmaillard/36e277e5cce310be2671 to your computer and use it in GitHub Desktop.
twittering-connection-type-table as a defcustom entry
;; First attempt:
(defun twittering-connection-build-customize-option ()
(list 'repeat
(list
'list :tag "Configure connection method"
'(repeat
:tag "Name"
(choice
(cons :tag "Check test method"
(const :format "" :check)
(set (const :tag "No matter what" t)
function))
(cons :tag "Display name"
(const :format "" :display-name)
string)
(cons :tag "HTTPS connection method"
(const :format "" :https)
(set (const :tag "None" nil)
function))
(cons :tag "Send HTTP request function"
(const :format "" :send-http-request)
function)
(cons :tag "Pre process buffer"
(const :format "" :pre-process-buffer)
function))))))
(defcustom twittering-connection-type-table
'((native (check . t)
(https . twittering-start-http-session-native-tls-p)
(send-http-request . twittering-send-http-request-native)
(pre-process-buffer . twittering-pre-process-buffer-native))
(curl (check . twittering-start-http-session-curl-p)
(https . twittering-start-http-session-curl-https-p)
(send-http-request . twittering-send-http-request-curl)
(pre-process-buffer . twittering-pre-process-buffer-curl))
(wget (check . twittering-start-http-session-wget-p)
(https . t)
(send-http-request . twittering-send-http-request-wget)
(pre-process-buffer . twittering-pre-process-buffer-wget))
(urllib-http
(display-name . "urllib")
(check . twittering-start-http-session-urllib-p)
(https . nil)
(send-http-request . twittering-send-http-request-urllib)
(pre-process-buffer . twittering-pre-process-buffer-urllib))
(urllib-https
(display-name . "urllib")
(check . twittering-start-http-session-urllib-p)
(https . twittering-start-http-session-urllib-https-p)
(send-http-request . twittering-send-http-request-urllib)
(pre-process-buffer . twittering-pre-process-buffer-urllib)))
"A list of alist of connection methods."
:group 'twittering-mode
:type (twittering-connection-build-customize-option))
@xmaillard
Copy link
Author

Here is another attempt:

(defun twittering-connection-build-customize-option ()
  (list 'repeat 
    (list
     'cons
     '(symbol :tag "Connection symbol" :value "")
     '(repeat
       :tag "Connection method defintion"
       (choice
        (cons :tag "Check test method"
          (const :format "" check)
          (choice :value t (const :tag "Do not check" t)
              (function :tag "Check function")))
        (cons :tag "Display name"
          (const :format "" display-name)
          string)
        (cons :tag "HTTPS connection method"
          (const :format "" https)
          (choice :value nil (const :tag "Same as HTTP" nil)
              (function :tag "HTTPS function")))
        (cons :tag "Send HTTP request function"
          (const :format "" send-http-request)
          function)
        (cons :tag "Pre process buffer"
          (const :format "" pre-process-buffer)
          function))))))

This will generate an acceptable value. Could it be better written ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment