Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, I second the recommendation that you store the passwords in an actual alist and, if necessary, set whatever variables you need to based on that.</p> <p>That aside, here's another solution that tries to break things out a bit. The <code>-partition</code> function is from the <a href="https://github.com/magnars/dash.el" rel="nofollow">dash.el</a> library, which I highly recommend.</p> <p>You don't really need to "walk" the code, just <code>read</code> it in and check if its <code>car</code> is <code>setq</code>. The remainder of the form should then be alternating symbols and strings, so you simply partition them by 2 and you have your alist. (Note that the "pairs" will be proper lists as opposed to the dotted pairs in Sean's solution).</p> <pre><code>(defun setq-form-p (form) (eq (car form) 'setq)) (defun read-file (filename) (with-temp-buffer (insert-file-literally filename) (read (buffer-substring-no-properties 1 (point-max))))) (defun credential-pairs (form) (-partition 2 (cdr form))) (defun read-credentials-alist (filename) (let ((form (read-file filename))) (credential-pairs form))) ;; usage: (read-credentials-alist "passwords.el") </code></pre> <p>Alternatively, here's how it would work if you already had the passwords in an alist, like so</p> <pre><code>(defvar *passwords* '((twitter-password "Secret") (github-password "Sauce"))) </code></pre> <p>And then wanted to set the variable <code>twitter-password</code> to <code>"Sauce"</code> and so on. You would just map over it:</p> <pre><code>(mapcar #'(lambda (pair) (let ((name (car pair)) (value (cadr pair))) (set name value))) *passwords*) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload