* Additon to tumme.el
@ 2006-07-16 9:21 Mathias Dahl
2006-07-16 12:35 ` David Kastrup
2006-07-17 1:41 ` Richard Stallman
0 siblings, 2 replies; 6+ messages in thread
From: Mathias Dahl @ 2006-07-16 9:21 UTC (permalink / raw)
I would like to add the following code to tumme.el. It provides a
facility to very easily edit file tags and comments of image files in
a buffer using widgets. It is actually quite simple but in my opinion
a very nice piece of functionality for end users. The code does not
affect any old functionality in tumme (only new functions and
variables are added). I also propose yet another key binding (C-t e)
in Dired that will call `tumme-dired-edit-comment-and-tags'.
Is it a bad time now for things like this?
;;;; Code begins here
(require 'widget)
(eval-when-compile
(require 'wid-edit))
(defvar tumme-widget-list nil
"List to keep track of meta data in edit buffer")
(defun tumme-dired-edit-comment-and-tags ()
"Edit comment and tags of current or marked image files.
Edit comment and tags for all marked image files in an
easy-to-use form."
(interactive)
(setq tumme-widget-list nil)
;; Setup buffer.
(let ((files (dired-get-marked-files)))
(switch-to-buffer "*Tumme Edit Meta Data*")
(kill-all-local-variables)
(make-local-variable 'widget-example-repeat)
(let ((inhibit-read-only t))
(erase-buffer))
(remove-overlays)
;; Some help for the user.
(widget-insert
"\nEdit comments and tags for each image. Separate multiple tags
with a comma. Move forward between fields using TAB or RET.
Move to the previous field using backtab (S-TAB). Save by
activating the Save button at the bottom of the form or cancel
the operation by activating the Cancel button.\n\n")
;; Here comes all images and a comment and tag field for each
;; image.
(mapc
(lambda (file)
(let* ((thumb-file (tumme-thumb-name file))
(img (create-image thumb-file))
comment-widget tag-widget)
(insert-image img)
(widget-insert "\n\nComment: ")
(setq comment-widget
(widget-create 'editable-field
:size 60
:format "%v "
:value (or (tumme-get-comment file) "")))
(widget-insert "\nTags: ")
(setq tag-widget
(widget-create 'editable-field
:size 60
:format "%v "
:value (or (mapconcat
(lambda (tag)
tag)
(tumme-list-tags file)
",") "")))
;; Save information in all widgets so that we can use it when
;; the user saves the form.
(setq tumme-widget-list
(append tumme-widget-list
(list (list file comment-widget tag-widget))))
(widget-insert "\n\n")))
files))
;; Footer with Save and Cancel button.
(widget-insert "\n")
(widget-create 'push-button
:notify
(lambda (&rest ignore)
(tumme-save-information-from-widgets)
(bury-buffer)
(message "Done."))
"Save")
(widget-insert " ")
(widget-create 'push-button
:notify
(lambda (&rest ignore)
(bury-buffer)
(message "Operation canceled."))
"Cancel")
(widget-insert "\n")
(use-local-map widget-keymap)
(widget-setup)
;; Jump to the first widget.
(widget-forward 1))
(defun tumme-save-information-from-widgets ()
"Save information found in `tumme-widget-list'.
Use the information in `tumme-widget-list' to save comments and
tags to their respective image file. Internal function used by
`tumme-dired-edit-comment-and-tags'."
(mapc
(lambda (x)
(let ((file (car x))
(comment (widget-value (cadr x)))
(tags (widget-value (caddr x))))
(tumme-write-comment file comment)
(mapc
(lambda (tag)
(tumme-write-tag file tag))
(split-string tags ","))))
tumme-widget-list))
;;;; Code ends here
/Mathias
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Additon to tumme.el
2006-07-16 9:21 Additon to tumme.el Mathias Dahl
@ 2006-07-16 12:35 ` David Kastrup
2006-07-16 22:43 ` Mathias Dahl
2006-07-17 1:41 ` Richard Stallman
1 sibling, 1 reply; 6+ messages in thread
From: David Kastrup @ 2006-07-16 12:35 UTC (permalink / raw)
Cc: emacs-devel
"Mathias Dahl" <mathias.dahl@gmail.com> writes:
Just a code remark:
> (mapc
> (lambda (file)
> (let* ((thumb-file (tumme-thumb-name file))
> (img (create-image thumb-file))
> comment-widget tag-widget)
> (insert-image img)
[Kilometers of code...]
> files))
I'd rather use
(let (thumb-file img comment-widget tag-widget)
(dolist (file files)
(setq thumb-file (tumme-thumb-name file)
img (create-image thumb-file))
...
That is much more efficient (probably not a concern here) and also
much more readable, since the "files" does not crop up at some point
way down in the hierarchy.
The main point about efficiency is that (mapc (lambda...)) has to
create and destroy bindings for every single iteration. Moving the
bindings of thumb-file etc out of the loop is also an efficiency
thing.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Additon to tumme.el
2006-07-16 12:35 ` David Kastrup
@ 2006-07-16 22:43 ` Mathias Dahl
0 siblings, 0 replies; 6+ messages in thread
From: Mathias Dahl @ 2006-07-16 22:43 UTC (permalink / raw)
Cc: emacs-devel
> I'd rather use
>
> (let (thumb-file img comment-widget tag-widget)
> (dolist (file files)
> (setq thumb-file (tumme-thumb-name file)
> img (create-image thumb-file))
That seems to work well. Thanks for the explanation about efficiency!
Still I want to know if anyone oppose the change per-se, this late. I
don't think many on this list has tried Tumme, but if you have, please
try this out and see how it is as easy to work with as I think it is.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Additon to tumme.el
2006-07-16 9:21 Additon to tumme.el Mathias Dahl
2006-07-16 12:35 ` David Kastrup
@ 2006-07-17 1:41 ` Richard Stallman
2006-07-17 10:46 ` Mathias Dahl
1 sibling, 1 reply; 6+ messages in thread
From: Richard Stallman @ 2006-07-17 1:41 UTC (permalink / raw)
Cc: emacs-devel
I think it is ok to add this. It is self-contained and won't break
anything else, so it shouldn't delay our pretest.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-07-20 9:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-16 9:21 Additon to tumme.el Mathias Dahl
2006-07-16 12:35 ` David Kastrup
2006-07-16 22:43 ` Mathias Dahl
2006-07-17 1:41 ` Richard Stallman
2006-07-17 10:46 ` Mathias Dahl
2006-07-20 9:28 ` Mathias Dahl
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.