* extract regexp @ 2003-04-17 16:20 Bruce Ingalls 2003-04-17 17:11 ` lawrence mitchell 0 siblings, 1 reply; 6+ messages in thread From: Bruce Ingalls @ 2003-04-17 16:20 UTC (permalink / raw) I am trying to read a server name from Mozilla's prefs.js into a variable. The format of the string is user_pref("mail.server.server1.hostname", "pop.server.com"); So the regular expression is something like user_pref\\("mail\\.server\\.server1\\.hostname", "([^"]+)"\\); How do I, for this case, read the file prefs.js, and load pop.server.com into a variable, "my-server"? Thanks ahead. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: extract regexp 2003-04-17 16:20 extract regexp Bruce Ingalls @ 2003-04-17 17:11 ` lawrence mitchell 2003-04-17 17:31 ` Kevin Rodgers 0 siblings, 1 reply; 6+ messages in thread From: lawrence mitchell @ 2003-04-17 17:11 UTC (permalink / raw) Bruce Ingalls wrote: > I am trying to read a server name from Mozilla's prefs.js into a variable. > The format of the string is > user_pref("mail.server.server1.hostname", "pop.server.com"); > So the regular expression is something like > user_pref\\("mail\\.server\\.server1\\.hostname", "([^"]+)"\\); > How do I, for this case, read the file prefs.js, and load > pop.server.com into > a variable, "my-server"? (let ((str "user_pref(\"mail.server.server1.hostname\", \"pop.server.com\");") server) (when (string-match (concat "user_pref(\"mail\\.server\\.server1\\.hostname\", " "\"\\([^\"]+\\)\");") str) (setq server (match-string 1 str)))) => "pop.server.com" to read in the file, do something like: (with-temp-buffer (insert-file-contents-literally "prefs.js") (goto-char (point-min)) (condition-case err (re-search-forward regexp) (error (error "%s not found." regexp))) (setq server (match-string 1))) where regexp is as above. -- lawrence mitchell <wence@gmx.li> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: extract regexp 2003-04-17 17:11 ` lawrence mitchell @ 2003-04-17 17:31 ` Kevin Rodgers 2003-04-22 14:08 ` Bruce Ingalls 0 siblings, 1 reply; 6+ messages in thread From: Kevin Rodgers @ 2003-04-17 17:31 UTC (permalink / raw) lawrence mitchell wrote: > (with-temp-buffer > (insert-file-contents-literally "prefs.js") > (goto-char (point-min)) > (condition-case err > (re-search-forward regexp) > (error (error "%s not found." regexp))) > (setq server (match-string 1))) Why not just let re-search-forward report the error itself? Or do (if (re-search-forward regexp nil t) (setq server (match-string 1)) (do-something-else)) -- <a href="mailto:<kevin.rodgers@ihs.com>">Kevin Rodgers</a> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: extract regexp 2003-04-17 17:31 ` Kevin Rodgers @ 2003-04-22 14:08 ` Bruce Ingalls 2003-04-22 16:28 ` Kevin Rodgers 0 siblings, 1 reply; 6+ messages in thread From: Bruce Ingalls @ 2003-04-22 14:08 UTC (permalink / raw) Kevin Rodgers wrote: > lawrence mitchell 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\", \"\\([^\"]+\\)") 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. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: extract regexp 2003-04-22 14:08 ` Bruce Ingalls @ 2003-04-22 16:28 ` Kevin Rodgers 2003-04-22 17:31 ` Bruce Ingalls 0 siblings, 1 reply; 6+ messages in thread From: Kevin Rodgers @ 2003-04-22 16:28 UTC (permalink / raw) 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:<kevin.rodgers@ihs.com>">Kevin Rodgers</a> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: extract regexp 2003-04-22 16:28 ` Kevin Rodgers @ 2003-04-22 17:31 ` Bruce Ingalls 0 siblings, 0 replies; 6+ messages in thread From: Bruce Ingalls @ 2003-04-22 17:31 UTC (permalink / raw) Kevin Rodgers wrote: > Bruce Ingalls wrote: >> 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? It's in prefs.js. I didn't say everything about how I was using this code, and I suspect that your correction (while appreciated) is not appropriate. There is one nonstandard regex that I pass in, but otherwise, I can use a normal string for the key, and concat it. I'm sure the previous line sounds like rambling, and I likely need to explain myself in code. You can see how I am actually using it, in the EMacro 2.7 beta at <url: http://sf.net/projects/emacro/ > in the files e-config.el and e-functions.el I also use this function to import (the first possible) nntp news server, as well as login IDs, etc. Here are excerpts from my prefs.js file, with names slightly altered for protection: user_pref("mail.server.server1.directory", "/home/bingalls/.mozilla/default/mo3abcd.slt/Mail/pop-server.aol.com"); user_pref("mail.server.server1.download_on_biff", true); user_pref("mail.server.server1.empty_trash_on_exit", true); user_pref("mail.server.server1.hostname", "pop-server.aol.com"); user_pref("mail.server.server1.spamLoggingEnabled", true); user_pref("mail.server.server1.type", "pop3"); //... user_pref("mail.server.server3.directory", "/home/bingalls/.mozilla/default/mo3abcd.slt/News/news-server.aol.com"); user_pref("mail.server.server3.hostname", "news-server.aol.com"); user_pref("mail.server.server3.max_cached_connections", 2); user_pref("mail.server.server3.name", "news-server.aol.com"); user_pref("mail.server.server3.newsrc.file", "/home/bingalls/.mozilla/default/mo3abcd.slt/News/newsrc-news-server.aol.com"); user_pref("mail.server.server3.type", "nntp"); Thus, the mail.server.server?.type in prefs.js tells me that I have a POP3, IMAP, NNTP or local folder. The '*.type' follows the server name, by a variable number of lines. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2003-04-22 17:31 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2003-04-17 16:20 extract regexp Bruce Ingalls 2003-04-17 17:11 ` lawrence mitchell 2003-04-17 17:31 ` Kevin Rodgers 2003-04-22 14:08 ` Bruce Ingalls 2003-04-22 16:28 ` Kevin Rodgers 2003-04-22 17:31 ` Bruce Ingalls
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.