Skip to content

Development Resources

Sean Allred edited this page Nov 13, 2014 · 5 revisions

Development Resources

Development Tools

In #40, sx-assoc-let was introduced to make data access more reasable when working with the associations lists that functions like sx-request-make return:

((site_type . "main_site")
 (name . "Stack Overflow")
 (api_site_parameter . "stackoverflow")
 (site_url . "http://stackoverflow.com"))

To use this as is (say, bound to data), we would need to use a complicated let-binding:

(let ((site_type          (cdr (assoc 'site_type          data)))
      (name               (cdr (assoc 'name               data)))
      (api_site_parameter (cdr (assoc 'api_site_parameter data)))
      (site_url           (cdr (assoc 'site_url           data))))
  (message "%S %S %S %S"
           site_type name api_site_parameter site_url))

With sx-assoc-let, this complicated structure becomes

(sx-assoc-let data
  (message "%S %S %S %S"
           .site_type .name .api_site_parameter .site_url))

Much cleaner, don’t you think? The macro gathers every symbol the begins with . and let-binds them to the corresponding form. For .symbol, we would see (cdr (assoc 'symbol data)) as its binding.

Since this is an easily recognizable pattern, it’s recommended that the following font-lock rule is added to your development environment:

(font-lock-add-keywords
 'emacs-lisp-mode
 '(("\\_<\\.\\(?:\\sw\\|\\s_\\)+\\_>" 0 font-lock-builtin-face)))

Useful Links

Editing

Requests

Authentication Tests

Clone this wiki locally