* Re: Recent documents: Emacs and GNOME integration
[not found] <1147396844.567992.55920@i40g2000cwc.googlegroups.com>
@ 2006-05-13 4:51 ` Richard Stallman
2006-05-17 7:50 ` Mathias Dahl
0 siblings, 1 reply; 15+ messages in thread
From: Richard Stallman @ 2006-05-13 4:51 UTC (permalink / raw)
Cc: emacs-devel
I'm not sure whether this has been already done, but here's a short
piece of elisp that adds every file open in emacs to the system-wide
list of recently used files. It will work for systems using Recent File
Storage Specification [1], such as GNOME [2]. Hopefully, GNOME Deskbar
Applet [3] will soon be able to use that list, giving you something
close to a system-wide equivalent of the excellent iswitchb mode [4].
(defun local-add-file-to-recent ()
(when buffer-file-name
(start-process "addtorecent.py" nil "addtorecent.py"
(concat "file://" buffer-file-name)
"text/plain")))
(add-hook 'find-file-hook 'local-add-file-to-recent)
That is quite clear and simple. But we would like to make it work
totally automatically, which means, Emacs needs to decide automatically
whether to do this or not.
How should Emacs decide that?
Would testing the existence of the executable addtorecent.py
in PATH be the right criterion?
Is there an Emacs package for xml manipulation (adding new nodes,
etc.)?
Recently-used.el [7] works in the opposite direction: it makes the
system-wide list of recently used files available to Emacs.
That could be a superior method, esp. if it allows Emacs to easily
determine whether this list exists on your machine. I expect it to
be more efficient also, but maybe addtorecent.py is fast enough.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
2006-05-13 4:51 ` Recent documents: Emacs and GNOME integration Richard Stallman
@ 2006-05-17 7:50 ` Mathias Dahl
2006-05-17 14:37 ` Piotr Zielinski
2006-05-17 20:08 ` Richard Stallman
0 siblings, 2 replies; 15+ messages in thread
From: Mathias Dahl @ 2006-05-17 7:50 UTC (permalink / raw)
Cc: Piotr Zielinski, emacs-devel
> (defun local-add-file-to-recent ()
> (when buffer-file-name
> (start-process "addtorecent.py" nil "addtorecent.py"
> (concat "file://" buffer-file-name)
> "text/plain")))
>
> (add-hook 'find-file-hook 'local-add-file-to-recent)
>
> That is quite clear and simple. But we would like to make it work
> totally automatically, which means, Emacs needs to decide automatically
> whether to do this or not.
> How should Emacs decide that?
What about:
1. If possible, rewrite addtorecent.py in Emacs Lisp.
2. Make a customizable option that will turn this feature on.
> Is there an Emacs package for xml manipulation (adding new nodes,
> etc.)?
Yes, there is. It's called xml.el. I am not sure which package it
comes from but I think it is included in CVS Emacs.
> Recently-used.el [7] works in the opposite direction: it makes the
> system-wide list of recently used files available to Emacs.
>
> That could be a superior method, esp. if it allows Emacs to easily
> determine whether this list exists on your machine. I expect it to
> be more efficient also, but maybe addtorecent.py is fast enough.
It would be nice but it really does the opposite of the above, does it
not? These are two different things; reading to GNOME's list of recent
files, and writing to it.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
2006-05-17 7:50 ` Mathias Dahl
@ 2006-05-17 14:37 ` Piotr Zielinski
2006-05-17 18:50 ` Stuart D. Herring
2006-05-17 23:12 ` Richard Stallman
2006-05-17 20:08 ` Richard Stallman
1 sibling, 2 replies; 15+ messages in thread
From: Piotr Zielinski @ 2006-05-17 14:37 UTC (permalink / raw)
Cc: rms, emacs-devel
On 17/05/06, Mathias Dahl <mathias.dahl@gmail.com> wrote:
> What about:
>
> 1. If possible, rewrite addtorecent.py in Emacs Lisp.
> 2. Make a customizable option that will turn this feature on.
That would be sensible, however, we'd need an emacs package for xml
manipulation. As far as I can see, xml.el is only a parser (can't
modify an existing xml tree).
> > Recently-used.el [7] works in the opposite direction: it makes the
> > system-wide list of recently used files available to Emacs.
> >
> > That could be a superior method, esp. if it allows Emacs to easily
> > determine whether this list exists on your machine. I expect it to
> > be more efficient also, but maybe addtorecent.py is fast enough.
>
> It would be nice but it really does the opposite of the above, does it
> not? These are two different things; reading to GNOME's list of recent
> files, and writing to it.
Yes, and in the name of interoperability both solutions should be
supported I think.
Piotr
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
2006-05-17 14:37 ` Piotr Zielinski
@ 2006-05-17 18:50 ` Stuart D. Herring
2006-05-17 19:01 ` Stuart D. Herring
2006-05-17 23:12 ` Richard Stallman
1 sibling, 1 reply; 15+ messages in thread
From: Stuart D. Herring @ 2006-05-17 18:50 UTC (permalink / raw)
Cc: emacs-devel
> That would be sensible, however, we'd need an emacs package for xml
> manipulation. As far as I can see, xml.el is only a parser (can't
> modify an existing xml tree).
xml.el contains the function `xml-debug-print' which inserts the XML
represented by the internal list form into a buffer. It's not very robust
(for instance, it doesn't attempt to substitute "&" back in for "&"),
but it seems to me that as long as retaining original formatting is
unnecessary, it could be made into a reasonable "Lisp (form of the data)
to XML" converter. Then you'd just use the standard Lisp capacities for
modifying/creating lists and you'd have XML modification capacity.
I'm not an expert on XML, but I could probably manage this if no one else
is any better. For starters, here's a trivial patch to print namespaced
tags instead of dying on them.
Hoping that the patch doesn't reveal that I shouldn't be touching this at
all,
Davis
*** xml.el.~1.53.~ 2006-02-06 07:33:36.000000000 -0700
--- xml.el 2006-05-17 12:48:39.000000000 -0600
***************
*** 118,123 ****
--- 118,129 ----
(car node))
+ (defsubst xml-node-name-as-string (node)
+ "Return the tag associated with NODE as a string."
+ (setq node (xml-node-name node))
+ (if (symbolp node) (symbol-name node)
+ (concat (car node) (cdr node))))
+
(defsubst xml-node-attributes (node)
"Return the list of attributes of NODE.
The list can be nil."
***************
*** 848,854 ****
The first line is indented with INDENT-STRING."
(let ((tree xml)
attlist)
! (insert indent-string ?< (symbol-name (xml-node-name tree)))
;; output the attribute list
(setq attlist (xml-node-attributes tree))
--- 854,860 ----
The first line is indented with INDENT-STRING."
(let ((tree xml)
attlist)
! (insert indent-string ?< (symbol-name (xml-node-name-as-string tree)))
;; output the attribute list
(setq attlist (xml-node-attributes tree))
***************
*** 875,881 ****
(when (not (and (null (cdr tree))
(stringp (car tree))))
(insert ?\n indent-string))
! (insert ?< ?/ (symbol-name (xml-node-name xml)) ?>))))
(provide 'xml)
--- 881,887 ----
(when (not (and (null (cdr tree))
(stringp (car tree))))
(insert ?\n indent-string))
! (insert ?< ?/ (symbol-name (xml-node-name-as-string xml)) ?>))))
(provide 'xml)
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
2006-05-17 18:50 ` Stuart D. Herring
@ 2006-05-17 19:01 ` Stuart D. Herring
0 siblings, 0 replies; 15+ messages in thread
From: Stuart D. Herring @ 2006-05-17 19:01 UTC (permalink / raw)
Cc: emacs-devel
I wrote:
> Hoping that the patch doesn't reveal that I shouldn't be touching this at
> all,
> Davis
Er, I think it did. But maybe this slightly different one won't:
*** xml.el.~1.53.~ 2006-02-06 07:33:36.000000000 -0700
--- xml.el 2006-05-17 13:00:44.000000000 -0600
***************
*** 118,123 ****
--- 118,129 ----
(car node))
+ (defsubst xml-node-name-as-string (node)
+ "Return the tag associated with NODE as a string."
+ (setq node (xml-node-name node))
+ (if (symbolp node) (symbol-name node)
+ (concat (car node) (cdr node))))
+
(defsubst xml-node-attributes (node)
"Return the list of attributes of NODE.
The list can be nil."
***************
*** 848,854 ****
The first line is indented with INDENT-STRING."
(let ((tree xml)
attlist)
! (insert indent-string ?< (symbol-name (xml-node-name tree)))
;; output the attribute list
(setq attlist (xml-node-attributes tree))
--- 854,860 ----
The first line is indented with INDENT-STRING."
(let ((tree xml)
attlist)
! (insert indent-string ?< (xml-node-name-as-string tree))
;; output the attribute list
(setq attlist (xml-node-attributes tree))
***************
*** 875,881 ****
(when (not (and (null (cdr tree))
(stringp (car tree))))
(insert ?\n indent-string))
! (insert ?< ?/ (symbol-name (xml-node-name xml)) ?>))))
(provide 'xml)
--- 881,887 ----
(when (not (and (null (cdr tree))
(stringp (car tree))))
(insert ?\n indent-string))
! (insert ?< ?/ (xml-node-name-as-string xml) ?>))))
(provide 'xml)
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
2006-05-17 7:50 ` Mathias Dahl
2006-05-17 14:37 ` Piotr Zielinski
@ 2006-05-17 20:08 ` Richard Stallman
1 sibling, 0 replies; 15+ messages in thread
From: Richard Stallman @ 2006-05-17 20:08 UTC (permalink / raw)
Cc: piotr.zielinski, emacs-devel
Is it easy to implement addtorecent.py in Emacs Lisp
using xml.el?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
2006-05-17 14:37 ` Piotr Zielinski
2006-05-17 18:50 ` Stuart D. Herring
@ 2006-05-17 23:12 ` Richard Stallman
2006-05-24 18:52 ` Kevin Rodgers
1 sibling, 1 reply; 15+ messages in thread
From: Richard Stallman @ 2006-05-17 23:12 UTC (permalink / raw)
Cc: emacs-devel, mathias.dahl
> 1. If possible, rewrite addtorecent.py in Emacs Lisp.
> 2. Make a customizable option that will turn this feature on.
That would be sensible, however, we'd need an emacs package for xml
manipulation. As far as I can see, xml.el is only a parser (can't
modify an existing xml tree).
Can you make it associate buffer positions with the parsed tree?
With that, it should be easy enough to do simple edits.
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?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
2006-05-17 23:12 ` Richard Stallman
@ 2006-05-24 18:52 ` Kevin Rodgers
2006-05-25 0:37 ` Richard Stallman
2006-05-25 17:02 ` Stuart D. Herring
0 siblings, 2 replies; 15+ messages in thread
From: Kevin Rodgers @ 2006-05-24 18:52 UTC (permalink / raw)
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 "<?xml version=\"1.0\" encoding=\""
recent-files-encoding
"\"?>")
(insert "\n" "<RecentFiles>")
(insert "\n" "</RecentFiles>"))
(goto-char (point-min))
(if (search-forward-regexp (concat "<URI>" (regexp-quote uri) "</URI>")
nil t)
;; then: Per the spec, only update the timestamp and add new groups:
(progn
(search-forward-regexp "<Timestamp>\\(.*\\)</Timestamp>")
(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*<Groups>")
(progn
(setq group-start (match-end 0))
(setq group-end (search-forward-regexp "</Groups>")))
(insert "\n" "<Groups>")
(setq group-start (point))
(insert "\n" "</Groups>")
(setq group-end (point-marker)))
(goto-char group-start)
(mapc (lambda (group)
(unless (save-excursion
(search-forward-regexp
(concat "<Group>"
(regexp-quote group)
"</Group>")
nil group-end))
(insert "\n" "<Group>" group "</Group>")))
groups))))
;; else: Insert the new item:
(search-forward "</RecentFiles>")
(goto-char (match-beginning 0))
(insert "<RecentItem>")
(insert "\n" "<URI>" uri "</URI>"
"\n" "<Mime-Type>" mime-type "</Mime-Type>"
"\n" "<Timestamp>" timestamp "</Timestamp>")
(when groups
(insert "\n" "<Groups>")
(mapc (lambda (group)
(insert "\n" "<Group>" group "</Group>"))
groups)
(insert "\n" "</Groups>"))
(when private
(insert "\n" "<Private/>"))
(insert "\n" "</RecentItem>" "\n"))
(save-buffer))
(or recent-buffer (kill-buffer (current-buffer))))))
--
Kevin
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
2006-05-24 18:52 ` Kevin Rodgers
@ 2006-05-25 0:37 ` Richard Stallman
2006-05-25 17:22 ` Bill Wohler
2006-05-25 17:02 ` Stuart D. Herring
1 sibling, 1 reply; 15+ messages in thread
From: Richard Stallman @ 2006-05-25 0:37 UTC (permalink / raw)
Cc: emacs-devel
So here's what I came up with based on the example in the spec:
Would people please try it and report if it works?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
2006-05-24 18:52 ` Kevin Rodgers
2006-05-25 0:37 ` Richard Stallman
@ 2006-05-25 17:02 ` Stuart D. Herring
1 sibling, 0 replies; 15+ messages in thread
From: Stuart D. Herring @ 2006-05-25 17:02 UTC (permalink / raw)
Cc: emacs-devel
> (insert "<RecentItem>")
> (insert "\n" "<URI>" uri "</URI>"
> "\n" "<Mime-Type>" mime-type "</Mime-Type>"
> "\n" "<Timestamp>" timestamp "</Timestamp>")
> (when groups
> (insert "\n" "<Groups>")
> (mapc (lambda (group)
> (insert "\n" "<Group>" group "</Group>"))
> groups)
> (insert "\n" "</Groups>"))
> (when private
> (insert "\n" "<Private/>"))
> (insert "\n" "</RecentItem>" "\n"))
Could this possibly be done by creating a proper Lisp structure
representing the XML data and then printing it (with the xml.el debugging
functions or something similar)? I think it'd be a good precedent to
build and print data structures rather than just generate flat text.
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
2006-05-25 0:37 ` Richard Stallman
@ 2006-05-25 17:22 ` Bill Wohler
2006-05-26 18:54 ` Kevin Rodgers
0 siblings, 1 reply; 15+ messages in thread
From: Bill Wohler @ 2006-05-25 17:22 UTC (permalink / raw)
Richard Stallman <rms@gnu.org> writes:
> So here's what I came up with based on the example in the spec:
>
> Would people please try it and report if it works?
Sort of, with the following modifications (patch for some appended):
1. Add find-file-hook (so it will be called). However, do we want to
add `update-recent-file' to the hook, or just call it from
`basic-save-file' directly?
2. Don't add the ~/.recently-used file to the list unless the user
opened it. The file should be invisible to the user.
3. Indent the XML to match the existing style of the file.
I didn't give much thought to the new names, so please review to check
for consistency and collisions.
In addition, the following also has to be done, but I was not readily
able to do so.
4. Suppress the "Wrote /home/wohler/.recently-used" message that
appears every time you visit a file.
5. Don't add backup files to the list.
The `private' and `groups' parameters aren't used by my hook.
Shouldn't `update-recent-file' at least set groups to "Emacs" if it
isn't given?
--- recent-files.el.orig 2006-05-25 09:15:13.000000000 -0700
+++ recent-files.el 2006-05-25 10:19:23.000000000 -0700
@@ -8,19 +8,28 @@
(require 'url-util)
(require 'mailcap)
+(defvar updating-recent-file nil
+ "Non-nil means `update-recent-file' should skip `recent-files-name'.
+It is set locally in `update-recent-file-item' and should NOT be
+set in any other fashion.")
+
(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)
+ (unless (and updating-recent-file
+ (equal file (expand-file-name 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)
@@ -35,7 +44,8 @@
(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)))
+ (recent-buffer (get-file-buffer recent-files-name))
+ (updating-recent-file t))
(save-excursion
(set-buffer (or recent-buffer (find-file-noselect
recent-files-name)))
@@ -62,9 +72,9 @@
(progn
(setq group-start (match-end 0))
(setq group-end (search-forward-regexp "</Groups>")))
- (insert "\n" "<Groups>")
+ (insert "\n" " <Groups>")
(setq group-start (point))
- (insert "\n" "</Groups>")
+ (insert "\n" " </Groups>")
(setq group-end (point-marker)))
(goto-char group-start)
(mapc (lambda (group)
@@ -74,23 +84,30 @@
(regexp-quote group)
"</Group>")
nil group-end))
- (insert "\n" "<Group>" group "</Group>")))
+ (insert "\n" " <Group>"
+ group " </Group>")))
groups))))
;; else: Insert the new item:
(search-forward "</RecentFiles>")
(goto-char (match-beginning 0))
- (insert "<RecentItem>")
- (insert "\n" "<URI>" uri "</URI>"
- "\n" "<Mime-Type>" mime-type "</Mime-Type>"
- "\n" "<Timestamp>" timestamp "</Timestamp>")
+ (insert " <RecentItem>")
+ (insert "\n" " <URI>" uri "</URI>"
+ "\n" " <Mime-Type>" mime-type "</Mime-Type>"
+ "\n" " <Timestamp>" timestamp "</Timestamp>")
(when groups
- (insert "\n" "<Groups>")
+ (insert "\n" " <Groups>")
(mapc (lambda (group)
- (insert "\n" "<Group>" group "</Group>"))
+ (insert "\n" " <Group>" group " </Group>"))
groups)
- (insert "\n" "</Groups>"))
+ (insert "\n" " </Groups>"))
(when private
- (insert "\n" "<Private/>"))
- (insert "\n" "</RecentItem>" "\n"))
+ (insert "\n" " <Private/>"))
+ (insert "\n" " </RecentItem>" "\n"))
(save-buffer))
(or recent-buffer (kill-buffer (current-buffer))))))
+
+(defun add-file-to-recent ()
+ (when buffer-file-name
+ (update-recent-file buffer-file-name)))
+
+(add-hook 'find-file-hook 'add-file-to-recent)
--
Bill Wohler <wohler@newt.com> http://www.newt.com/wohler/ GnuPG ID:610BD9AD
Maintainer of comp.mail.mh FAQ and MH-E. Vote Libertarian!
If you're passed on the right, you're in the wrong lane.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
2006-05-25 17:22 ` Bill Wohler
@ 2006-05-26 18:54 ` Kevin Rodgers
2006-05-30 15:46 ` Stuart D. Herring
0 siblings, 1 reply; 15+ messages in thread
From: Kevin Rodgers @ 2006-05-26 18:54 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 2276 bytes --]
Bill Wohler wrote:
> Richard Stallman <rms@gnu.org> writes:
>> Would people please try it and report if it works?
>
> Sort of, with the following modifications (patch for some appended):
>
> 1. Add find-file-hook (so it will be called). However, do we want to
> add `update-recent-file' to the hook, or just call it from
> `basic-save-file' directly?
I think the user should decide whether to take advantage of this
feature, by explicitly calling add-hook in ~/.emacs with find-file-hook
(and perhaps find-file-not-found-functions).
> 2. Don't add the ~/.recently-used file to the list unless the user
> opened it. The file should be invisible to the user.
Good point!
> 3. Indent the XML to match the existing style of the file.
Your patch doesn't match the existing style, it assumes that each
subelement is indented 4 spaces. I think the right way to do this would
be to call an indentation function, but do you really think it's worth
changing every occurrence of (insert "\n" "<Foo>") to
(newline-and-indent)
(insert "<Foo>")
> I didn't give much thought to the new names, so please review to check
> for consistency and collisions.
I changed the updating-recent-file variable to match the name of the
function it controls (update-recent-file), and I changed the
add-file-to-recent function to find-file-update-recent-file.
I suppose everything should have a recent-files- prefix, though.
> In addition, the following also has to be done, but I was not readily
> able to do so.
>
> 4. Suppress the "Wrote /home/wohler/.recently-used" message that
> appears every time you visit a file.
I don't think that message can be prevented, but perhaps the echo area
could be restored after ~/.recently-used is saved. Does anyone know how
to do that? Or will a simple (message "") call to clear it suffice?
> 5. Don't add backup files to the list.
That's easy with backup-file-name-p, so I've added that, plus a check
for auto-save files as well.
> The `private' and `groups' parameters aren't used by my hook.
> Shouldn't `update-recent-file' at least set groups to "Emacs" if it
> isn't given?
I've added user options to control that, with defaults to specify both.
Please give the attached version a try. Thanks,
--
Kevin
[-- Attachment #2: recent-files.el --]
[-- Type: text/plain, Size: 4394 bytes --]
(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)
(defvar update-recent-file t)
(defun update-recent-file (file &optional mime-type timestamp private groups)
"Add or update FILE's entry in `recent-files-name'."
(when update-recent-file
(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))
"application/octet-stream")
(or timestamp
(format "%.f" (float-time)))
private
groups)))
(defun update-recent-file-item (uri mime-type timestamp
&optional private groups)
;; Replace "<", "&", and ">" by "<", "&", and ">" resp.
;; in all string arguments (PRIVATE is boolean):
(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-files-name 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
;; Avoid adding `recent-files-name' to itself:
(let ((update-recent-file nil))
(find-file-noselect recent-files-name))))
(save-restriction
(widen)
(when (= (buffer-size) 0)
(goto-char (point-min))
(insert "<?xml version=\"1.0\" encoding=\""
recent-files-encoding
"\"?>")
(insert "\n" "<RecentFiles>")
(insert "\n" "</RecentFiles>"))
(goto-char (point-min))
(if (search-forward-regexp (concat "<URI>" (regexp-quote uri) "</URI>")
nil t)
;; Per the spec, only update the timestamp and add new groups:
(progn
(search-forward-regexp "<Timestamp>\\(.*\\)</Timestamp>")
(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*<Groups>")
(progn
(setq group-start (match-end 0))
(setq group-end (search-forward "</Groups>")))
(insert "\n" "<Groups>")
(setq group-start (point))
(insert "\n" "</Groups>")
(setq group-end (point-marker)))
(goto-char group-start)
(mapc (lambda (group)
(unless (save-excursion
(search-forward-regexp
(concat "<Group>"
(regexp-quote group)
"</Group>")
nil group-end))
(insert "\n" "<Group>" group "</Group>")))
groups))))
;; Else insert the new item:
(search-forward "</RecentFiles>")
(goto-char (match-beginning 0))
(insert "<RecentItem>")
(insert "\n" "<URI>" uri "</URI>"
"\n" "<Mime-Type>" mime-type "</Mime-Type>"
"\n" "<Timestamp>" timestamp "</Timestamp>")
(when groups
(insert "\n" "<Groups>")
(mapc (lambda (group)
(insert "\n" "<Group>" group "</Group>"))
groups)
(insert "\n" "</Groups>"))
(when private
(insert "\n" "<Private/>"))
(insert "\n" "</RecentItem>" "\n"))
(save-buffer))
(or recent-buffer (kill-buffer (current-buffer))))))
(defvar find-file-recent-files-private t
"If set, specify the \"<Private/>\" tag when adding visited files to \
`recent-files-name'.")
(defvar find-file-recent-files-groups '("Emacs")
"List of group names to add when updating visited files in \
`recent-files-name'.")
(defun find-file-update-recent-file ()
"Add the visited file to `recent-files-name'.
This function is designed to be added to `find-file-hook' and/or
`find-file-not-found-functions'."
(unless (or (null buffer-file-name)
(backup-file-name-p buffer-file-name)
(auto-save-file-name-p (file-name-nondirectory
buffer-file-name)))
(update-recent-file buffer-file-name nil nil
find-file-recent-files-private
find-file-recent-files-groups)))
;; (add-hook 'find-file-hook 'find-file-update-recent-file)
;; (add-hook 'find-file-not-found-functions 'find-file-update-recent-file)
[-- Attachment #3: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
2006-05-26 18:54 ` Kevin Rodgers
@ 2006-05-30 15:46 ` Stuart D. Herring
[not found] ` <20060530163850.34480.qmail@web51010.mail.yahoo.com>
0 siblings, 1 reply; 15+ messages in thread
From: Stuart D. Herring @ 2006-05-30 15:46 UTC (permalink / raw)
Cc: emacs-devel
> > 4. Suppress the "Wrote /home/wohler/.recently-used" message that
> > appears every time you visit a file.
>
> I don't think that message can be prevented, but perhaps the echo area
> could be restored after ~/.recently-used is saved. Does anyone know how
> to do that? Or will a simple (message "") call to clear it suffice?
`write-region' suppresses that message if its 5th argument is neither t,
nil, nor a string. Is that what you want?
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
[not found] ` <20060530163850.34480.qmail@web51010.mail.yahoo.com>
@ 2006-05-30 18:28 ` Stuart D. Herring
[not found] ` <20060530195948.37508.qmail@web51014.mail.yahoo.com>
0 siblings, 1 reply; 15+ messages in thread
From: Stuart D. Herring @ 2006-05-30 18:28 UTC (permalink / raw)
Cc: emacs-devel
>> > > 4. Suppress the "Wrote /home/wohler/.recently-used" message that
>> > > appears every time you visit a file.
>> >
>> > I don't think that message can be prevented, but perhaps the echo area
>> > could be restored after ~/.recently-used is saved. Does anyone know
>> how
>> > to do that? Or will a simple (message "") call to clear it suffice?
>>
>> `write-region' suppresses that message if its 5th argument is neither t,
>> nil, nor a string. Is that what you want?
>
> I don't think so, because that would also prevent last-save-file-modtime
> from being set and the buffer would still be marked as modified -- right?
Is it important that the ~/.recently-used file be -visited- rather than
merely written? It is, however, probably a misfeature that file-visiting
and message-printing are coupled like that. You could always use
(let (message-log-max) (with-temp-message (or (current-message) "")
(foo))) to, more or less, "sweep under the carpet" foo's messages (though
they'll still be visible during foo's execution).
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Recent documents: Emacs and GNOME integration
[not found] ` <20060530195948.37508.qmail@web51014.mail.yahoo.com>
@ 2006-05-30 21:10 ` Stuart D. Herring
0 siblings, 0 replies; 15+ messages in thread
From: Stuart D. Herring @ 2006-05-30 21:10 UTC (permalink / raw)
Cc: emacs-devel
> I was going to respond that the ~/.recently-used file has to be visited
> in order to make the necessary changes, and that it's only important
> that the buffer's state matches the file in the case that the user had
> previously visited the file himself/herself. But your question made me
> realize that the file's contents could be updated in a temporary buffer
> and then written to disk -- except that the question of what to do in
> case the file is already visited in a buffer becomes even trickier,
> especially if the buffer has been modified.
Just see if the file is already being visited (`get-file-buffer') and use
its visiting buffer (complete with the "written" message) if so. The only
problem then is if the user has made that buffer incompatibly formatted.
But then again, this could already happen with the file, so it's not an
additional difficulty.
I might also point out that the other things `write-region' does without
the message-suppressing VISIT argument can be done with
`set-visited-file-name' and `set-visited-file-modtime'. Maybe that helps
when doing it the way you want?
Davis
PS - You may realize it perfectly well, but in case you don't: you haven't
been including emacs-devel in your posts as far as I can tell.
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2006-05-30 21:10 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1147396844.567992.55920@i40g2000cwc.googlegroups.com>
2006-05-13 4:51 ` Recent documents: Emacs and GNOME integration Richard Stallman
2006-05-17 7:50 ` Mathias Dahl
2006-05-17 14:37 ` Piotr Zielinski
2006-05-17 18:50 ` Stuart D. Herring
2006-05-17 19:01 ` Stuart D. Herring
2006-05-17 23:12 ` Richard Stallman
2006-05-24 18:52 ` Kevin Rodgers
2006-05-25 0:37 ` Richard Stallman
2006-05-25 17:22 ` Bill Wohler
2006-05-26 18:54 ` Kevin Rodgers
2006-05-30 15:46 ` Stuart D. Herring
[not found] ` <20060530163850.34480.qmail@web51010.mail.yahoo.com>
2006-05-30 18:28 ` Stuart D. Herring
[not found] ` <20060530195948.37508.qmail@web51014.mail.yahoo.com>
2006-05-30 21:10 ` Stuart D. Herring
2006-05-25 17:02 ` Stuart D. Herring
2006-05-17 20:08 ` Richard Stallman
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.