help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: extract regexp


From: Kevin Rodgers
Subject: Re: extract regexp
Date: Tue, 22 Apr 2003 10:28:40 -0600
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2

Bruce Ingalls wrote:

Thanks for your help. This is what I ended up with:

(setq moz-prefs-filename
    "~/.mozilla/...[random name].../default/prefs.js")

(defun moz-get-prefs (key)
  "Returns value in prefs.js corresponding to key. key is line in prefs.js
file, up to desired value (which is followed by closing double quote).
Returns nil, if no key or value not found. Requires the variable
moz-prefs-filename, which is set in e-config.el."

  (with-temp-buffer
    (condition-case err
    (insert-file-contents-literally moz-prefs-filename)
      (error 'nil))
    (if (re-search-forward key nil t)
    (setq server (match-string 1))
      'nil)))

And here is how I call it:

  (moz-get-prefs
       "user_pref(\"mail.server.server1.hostname\", \"\\([^\"]+\\)")


That's rather awkward Emacs Lisp style.  I would write it as:

(defvar moz-user-pref-file "~/.mozilla/...[random name].../default/prefs.js")

(defun moz-user-pref (key)
  "Return the user_pref value for KEY in the `moz-user-pref-file' file."
  (let ((key-regexp (format "user_pref(\"%s\", \"\\([^\"]+\\)\")" key)))
    (with-temp-buffer
     (condition-case nil
         (insert-file-contents-literally moz-user-pref-file)
       (error nil))
     (if (re-search-forward key-regexp nil t)
         (match-string 1)))))

(setq server
      (moz-user-pref "mail.server.server1.hostname"))

Unfortunately, it gets a little more tricky, as I should check that
mail.server.server*.type
is pop3 or imap, and not nntp, but this is good enough.

Is that information in the prefs.js file, or do you have to querey the server?


--
<a href="mailto:&lt;kevin.rodgers&#64;ihs.com&gt;";>Kevin Rodgers</a>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]