From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.devel Subject: Re: Recent documents: Emacs and GNOME integration Date: Wed, 24 May 2006 12:52:25 -0600 Organization: IHS Message-ID: References: <1147396844.567992.55920@i40g2000cwc.googlegroups.com> <7dbe73ed0605170050k53a88da4j81d723f2ea0202da@mail.gmail.com> <3c12eb8d0605170737p4f172fabya587f640eebbbbe6@mail.gmail.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1148496856 16381 80.91.229.2 (24 May 2006 18:54:16 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 24 May 2006 18:54:16 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 24 20:54:15 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FiyUe-000478-4f for ged-emacs-devel@m.gmane.org; Wed, 24 May 2006 20:54:04 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FiyUd-0000OB-LT for ged-emacs-devel@m.gmane.org; Wed, 24 May 2006 14:54:03 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FiyUS-0000NK-H8 for emacs-devel@gnu.org; Wed, 24 May 2006 14:53:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FiyUR-0000Mt-MV for emacs-devel@gnu.org; Wed, 24 May 2006 14:53:52 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FiyUR-0000Mp-Hf for emacs-devel@gnu.org; Wed, 24 May 2006 14:53:51 -0400 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1FiyYv-000898-J1 for emacs-devel@gnu.org; Wed, 24 May 2006 14:58:30 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1FiyU2-00041B-3p for emacs-devel@gnu.org; Wed, 24 May 2006 20:53:26 +0200 Original-Received: from 207.167.42.206 ([207.167.42.206]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 24 May 2006 20:53:26 +0200 Original-Received: from ihs_4664 by 207.167.42.206 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 24 May 2006 20:53:26 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-To: emacs-devel@gnu.org Original-Lines: 115 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 207.167.42.206 User-Agent: Thunderbird 1.5.0.2 (Windows/20060308) In-Reply-To: X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:55221 Archived-At: Richard Stallman wrote: > If the structure of the recent files list is simple enough, > maybe it is easy to edit it correctly even without having the > sophistication to parse xml. Would someone like to take a look > and try to write this? I believe you are correct, but the spec is terribly imprecise: there is no DTD or schema, no formal specification of the various elements' content, numerous occurrences of "should", etc. I sent a message to the xdg@lists.freedesktop.org mailing list asking for clarification, but it never even showed up in the archive (http://lists.freedesktop.org/archives/xdg/). So here's what I came up with based on the example in the spec: (provide 'recent-files) ;; See http://standards.freedesktop.org/recent-file-spec/recent-file-spec-0.2.html#storage (defconst recent-files-encoding "UTF-8") (defconst recent-files-name "~/.recently-used") (defconst recent-files-limit 500) (require 'url-util) (require 'mailcap) (defun update-recent-file (file &optional mime-type timestamp private &rest groups) "Add or update FILE's entry in `recent-files-name'." (apply 'update-recent-file-item (concat "file://" (mapconcat 'url-hexify-string (split-string (expand-file-name file) "/") "/")) (or mime-type (cdr (assoc (file-name-extension file t) mailcap-mime-extensions))) (or timestamp (format "%.f" (float-time))) private groups)) ; (cons "Emacs" groups) (defun update-recent-file-item (uri mime-type timestamp &optional private &rest groups) ;; Replace "<", "&", and ">" by "<", "&", and ">" resp. ;; in all string arguments (URI, MIME-TYPE, TIMESTAMP, and GROUPS) ;; but not the boolean argument (PRIVATE): (setq uri (url-insert-entities-in-string uri) mime-type (url-insert-entities-in-string mime-type) timestamp (url-insert-entities-in-string timestamp) groups (mapcar 'url-insert-entities-in-string groups)) ;; Make sure recent-file is opened and saved in the correct encoding: (let* ((coding-system-for-read (intern (downcase recent-files-encoding))) (coding-system-for-write coding-system-for-read) (coding-system-require-warning t) (recent-buffer (get-file-buffer recent-files-name))) (save-excursion (set-buffer (or recent-buffer (find-file-noselect recent-files-name))) (save-restriction (widen) (when (= (buffer-size) 0) (goto-char (point-min)) (insert "") (insert "\n" "") (insert "\n" "")) (goto-char (point-min)) (if (search-forward-regexp (concat "" (regexp-quote uri) "") nil t) ;; then: Per the spec, only update the timestamp and add new groups: (progn (search-forward-regexp "\\(.*\\)") (replace-match timestamp t t nil 1) (goto-char (match-end 0)) ; end-of-line (when groups (let (group-start group-end) (if (looking-at "\n*") (progn (setq group-start (match-end 0)) (setq group-end (search-forward-regexp ""))) (insert "\n" "") (setq group-start (point)) (insert "\n" "") (setq group-end (point-marker))) (goto-char group-start) (mapc (lambda (group) (unless (save-excursion (search-forward-regexp (concat "" (regexp-quote group) "") nil group-end)) (insert "\n" "" group ""))) groups)))) ;; else: Insert the new item: (search-forward "") (goto-char (match-beginning 0)) (insert "") (insert "\n" "" uri "" "\n" "" mime-type "" "\n" "" timestamp "") (when groups (insert "\n" "") (mapc (lambda (group) (insert "\n" "" group "")) groups) (insert "\n" "")) (when private (insert "\n" "")) (insert "\n" "" "\n")) (save-buffer)) (or recent-buffer (kill-buffer (current-buffer)))))) -- Kevin