diff options
| author | Mathias Dahl | 2006-05-27 11:06:06 +0000 |
|---|---|---|
| committer | Mathias Dahl | 2006-05-27 11:06:06 +0000 |
| commit | 8d20653feeb6d125386855f65a50720f2e5f5dfb (patch) | |
| tree | 17bfc495c0232a4f1c5d52a4018d1ba6e8bd71ac | |
| parent | 63910b2311ccfd008de65a72e27eebc20033d088 (diff) | |
| download | emacs-8d20653feeb6d125386855f65a50720f2e5f5dfb.tar.gz emacs-8d20653feeb6d125386855f65a50720f2e5f5dfb.zip | |
* tumme.el: Replace a lot of `if ... progn' with `when'.
* tumme.el (tumme-delete-tag): Rename from `tumme-tag-remove'.
(tumme-setup-dired-keybindings): Change `tumme-add-remove' to
`tumme-delete-tag'.
| -rw-r--r-- | lisp/tumme.el | 192 |
1 files changed, 90 insertions, 102 deletions
diff --git a/lisp/tumme.el b/lisp/tumme.el index 99f14f3ccb0..8358986cca7 100644 --- a/lisp/tumme.el +++ b/lisp/tumme.el | |||
| @@ -881,10 +881,9 @@ displayed." | |||
| 881 | (end-of-line) | 881 | (end-of-line) |
| 882 | (setq end (point)) | 882 | (setq end (point)) |
| 883 | (beginning-of-line) | 883 | (beginning-of-line) |
| 884 | (if (not (search-forward (format ";%s" tag) end t)) | 884 | (when (not (search-forward (format ";%s" tag) end t)) |
| 885 | (progn | 885 | (end-of-line) |
| 886 | (end-of-line) | 886 | (insert (format ";%s" tag)))) |
| 887 | (insert (format ";%s" tag))))) | ||
| 888 | (goto-char (point-max)) | 887 | (goto-char (point-max)) |
| 889 | (insert (format "\n%s;%s" file tag)))) | 888 | (insert (format "\n%s;%s" file tag)))) |
| 890 | files) | 889 | files) |
| @@ -903,30 +902,27 @@ displayed." | |||
| 903 | (mapcar | 902 | (mapcar |
| 904 | (lambda (file) | 903 | (lambda (file) |
| 905 | (goto-char (point-min)) | 904 | (goto-char (point-min)) |
| 906 | (if (search-forward-regexp | 905 | (when (search-forward-regexp |
| 907 | (format "^%s" file) nil t) | 906 | (format "^%s" file) nil t) |
| 908 | (progn | 907 | (end-of-line) |
| 909 | (end-of-line) | 908 | (setq end (point)) |
| 910 | (setq end (point)) | 909 | (beginning-of-line) |
| 911 | (beginning-of-line) | 910 | (when (search-forward-regexp (format "\\(;%s\\)" tag) end t) |
| 912 | (if (search-forward-regexp (format "\\(;%s\\)" tag) end t) | 911 | (delete-region (match-beginning 1) (match-end 1)) |
| 913 | (progn | 912 | ;; Check if file should still be in the database. If |
| 914 | (delete-region (match-beginning 1) (match-end 1)) | 913 | ;; it has no tags or comments, it will be removed. |
| 915 | ;; Check if file should still be in the database. If | 914 | (end-of-line) |
| 916 | ;; it has no tags or comments, it will be removed. | 915 | (setq end (point)) |
| 917 | (end-of-line) | 916 | (beginning-of-line) |
| 918 | (setq end (point)) | 917 | (when (not (search-forward ";" end t)) |
| 919 | (beginning-of-line) | 918 | (kill-line 1) |
| 920 | (if (not (search-forward ";" end t)) | 919 | ;; If on empty line at end of buffer |
| 921 | (progn | 920 | (when (and (eobp) |
| 922 | (kill-line 1) | 921 | (looking-at "^$")) |
| 923 | ;; If on empty line at end of buffer | 922 | (delete-backward-char 1))))))) |
| 924 | (if (and (eobp) | 923 | files) |
| 925 | (looking-at "^$")) | 924 | (save-buffer) |
| 926 | (delete-backward-char 1))))))))) | 925 | (kill-buffer buf))) |
| 927 | files) | ||
| 928 | (save-buffer) | ||
| 929 | (kill-buffer buf)))) | ||
| 930 | 926 | ||
| 931 | (defun tumme-list-tags (file) | 927 | (defun tumme-list-tags (file) |
| 932 | "Read all tags for image FILE from the image database." | 928 | "Read all tags for image FILE from the image database." |
| @@ -934,17 +930,16 @@ displayed." | |||
| 934 | (let (end buf (tags "")) | 930 | (let (end buf (tags "")) |
| 935 | (setq buf (find-file tumme-db-file)) | 931 | (setq buf (find-file tumme-db-file)) |
| 936 | (goto-char (point-min)) | 932 | (goto-char (point-min)) |
| 937 | (if (search-forward-regexp | 933 | (when (search-forward-regexp |
| 938 | (format "^%s" file) nil t) | 934 | (format "^%s" file) nil t) |
| 939 | (progn | 935 | (end-of-line) |
| 940 | (end-of-line) | 936 | (setq end (point)) |
| 941 | (setq end (point)) | 937 | (beginning-of-line) |
| 942 | (beginning-of-line) | 938 | (if (search-forward ";" end t) |
| 943 | (if (search-forward ";" end t) | 939 | (if (search-forward "comment:" end t) |
| 944 | (if (search-forward "comment:" end t) | 940 | (if (search-forward ";" end t) |
| 945 | (if (search-forward ";" end t) | 941 | (setq tags (buffer-substring (point) end))) |
| 946 | (setq tags (buffer-substring (point) end))) | 942 | (setq tags (buffer-substring (point) end))))) |
| 947 | (setq tags (buffer-substring (point) end)))))) | ||
| 948 | (kill-buffer buf) | 943 | (kill-buffer buf) |
| 949 | (split-string tags ";")))) | 944 | (split-string tags ";")))) |
| 950 | 945 | ||
| @@ -1010,17 +1005,16 @@ use only useful if `tumme-track-movement' is nil." | |||
| 1010 | (let ((old-buf (current-buffer)) | 1005 | (let ((old-buf (current-buffer)) |
| 1011 | (dired-buf (tumme-associated-dired-buffer)) | 1006 | (dired-buf (tumme-associated-dired-buffer)) |
| 1012 | (file-name (tumme-original-file-name))) | 1007 | (file-name (tumme-original-file-name))) |
| 1013 | (if (and dired-buf file-name) | 1008 | (when (and dired-buf file-name) |
| 1014 | (progn | 1009 | (setq file-name (file-name-nondirectory file-name)) |
| 1015 | (setq file-name (file-name-nondirectory file-name)) | 1010 | (set-buffer dired-buf) |
| 1016 | (set-buffer dired-buf) | 1011 | (goto-char (point-min)) |
| 1017 | (goto-char (point-min)) | 1012 | (if (not (search-forward file-name nil t)) |
| 1018 | (if (not (search-forward file-name nil t)) | 1013 | (message "Could not track file") |
| 1019 | (message "Could not track file") | 1014 | (dired-move-to-filename) |
| 1020 | (dired-move-to-filename) | 1015 | (set-window-point |
| 1021 | (set-window-point | 1016 | (tumme-get-buffer-window dired-buf) (point))) |
| 1022 | (tumme-get-buffer-window dired-buf) (point))) | 1017 | (set-buffer old-buf)))) |
| 1023 | (set-buffer old-buf))))) | ||
| 1024 | 1018 | ||
| 1025 | (defun tumme-toggle-movement-tracking () | 1019 | (defun tumme-toggle-movement-tracking () |
| 1026 | "Turn on and off `tumme-track-movement'. | 1020 | "Turn on and off `tumme-track-movement'. |
| @@ -1039,24 +1033,22 @@ the other way around." | |||
| 1039 | (let ((file (dired-get-filename)) | 1033 | (let ((file (dired-get-filename)) |
| 1040 | (old-buf (current-buffer)) | 1034 | (old-buf (current-buffer)) |
| 1041 | prop-val found) | 1035 | prop-val found) |
| 1042 | (if (get-buffer tumme-thumbnail-buffer) | 1036 | (when (get-buffer tumme-thumbnail-buffer) |
| 1043 | (progn | 1037 | (set-buffer tumme-thumbnail-buffer) |
| 1044 | (set-buffer tumme-thumbnail-buffer) | 1038 | (goto-char (point-min)) |
| 1045 | (goto-char (point-min)) | 1039 | (while (and (not (eobp)) |
| 1046 | (while (and (not (eobp)) | 1040 | (not found)) |
| 1047 | (not found)) | 1041 | (if (and (setq prop-val |
| 1048 | (if (and (setq prop-val | 1042 | (get-text-property (point) 'original-file-name)) |
| 1049 | (get-text-property (point) 'original-file-name)) | 1043 | (string= prop-val file)) |
| 1050 | (string= prop-val file)) | 1044 | (setq found t)) |
| 1051 | (setq found t)) | 1045 | (if (not found) |
| 1052 | (if (not found) | 1046 | (forward-char 1))) |
| 1053 | (forward-char 1))) | 1047 | (when found |
| 1054 | (if found | 1048 | (set-window-point |
| 1055 | (progn | 1049 | (tumme-thumbnail-window) (point)) |
| 1056 | (set-window-point | 1050 | (tumme-display-thumb-properties)) |
| 1057 | (tumme-thumbnail-window) (point)) | 1051 | (set-buffer old-buf)))) |
| 1058 | (tumme-display-thumb-properties))) | ||
| 1059 | (set-buffer old-buf))))) | ||
| 1060 | 1052 | ||
| 1061 | (defun tumme-dired-next-line (&optional arg) | 1053 | (defun tumme-dired-next-line (&optional arg) |
| 1062 | "Call `dired-next-line', then track thumbnail. | 1054 | "Call `dired-next-line', then track thumbnail. |
| @@ -1081,29 +1073,27 @@ move ARG lines." | |||
| 1081 | (interactive) | 1073 | (interactive) |
| 1082 | ;; Before we move, make sure that there is an image two positions | 1074 | ;; Before we move, make sure that there is an image two positions |
| 1083 | ;; forward. | 1075 | ;; forward. |
| 1084 | (if (save-excursion | 1076 | (when (save-excursion |
| 1085 | (forward-char 2) | 1077 | (forward-char 2) |
| 1086 | (tumme-image-at-point-p)) | 1078 | (tumme-image-at-point-p)) |
| 1087 | (progn | 1079 | (forward-char) |
| 1088 | (forward-char) | 1080 | (while (and (not (eobp)) |
| 1089 | (while (and (not (eobp)) | 1081 | (not (tumme-image-at-point-p))) |
| 1090 | (not (tumme-image-at-point-p))) | 1082 | (forward-char)) |
| 1091 | (forward-char)) | 1083 | (if tumme-track-movement |
| 1092 | (if tumme-track-movement | 1084 | (tumme-track-original-file))) |
| 1093 | (tumme-track-original-file)))) | ||
| 1094 | (tumme-display-thumb-properties)) | 1085 | (tumme-display-thumb-properties)) |
| 1095 | 1086 | ||
| 1096 | (defun tumme-backward-char () | 1087 | (defun tumme-backward-char () |
| 1097 | "Move to previous image and display properties." | 1088 | "Move to previous image and display properties." |
| 1098 | (interactive) | 1089 | (interactive) |
| 1099 | (if (not (bobp)) | 1090 | (when (not (bobp)) |
| 1100 | (progn | 1091 | (backward-char) |
| 1101 | (backward-char) | 1092 | (while (and (not (bobp)) |
| 1102 | (while (and (not (bobp)) | 1093 | (not (tumme-image-at-point-p))) |
| 1103 | (not (tumme-image-at-point-p))) | 1094 | (backward-char)) |
| 1104 | (backward-char)) | 1095 | (if tumme-track-movement |
| 1105 | (if tumme-track-movement | 1096 | (tumme-track-original-file))) |
| 1106 | (tumme-track-original-file)))) | ||
| 1107 | (tumme-display-thumb-properties)) | 1097 | (tumme-display-thumb-properties)) |
| 1108 | 1098 | ||
| 1109 | (defun tumme-next-line () | 1099 | (defun tumme-next-line () |
| @@ -1664,11 +1654,10 @@ See also `tumme-line-up-dynamic'." | |||
| 1664 | (insert "\n") | 1654 | (insert "\n") |
| 1665 | (insert " ") | 1655 | (insert " ") |
| 1666 | (setq count (1+ count)) | 1656 | (setq count (1+ count)) |
| 1667 | (if (= count (- tumme-thumbs-per-row 1)) | 1657 | (when (= count (- tumme-thumbs-per-row 1)) |
| 1668 | (progn | 1658 | (forward-char) |
| 1669 | (forward-char) | 1659 | (insert "\n") |
| 1670 | (insert "\n") | 1660 | (setq count 0))))) |
| 1671 | (setq count 0)))))) | ||
| 1672 | (goto-char (point-min)))) | 1661 | (goto-char (point-min)))) |
| 1673 | 1662 | ||
| 1674 | (defun tumme-line-up-dynamic () | 1663 | (defun tumme-line-up-dynamic () |
| @@ -2097,19 +2086,18 @@ as initial value." | |||
| 2097 | (let (end buf comment-beg comment (base-name (file-name-nondirectory file))) | 2086 | (let (end buf comment-beg comment (base-name (file-name-nondirectory file))) |
| 2098 | (setq buf (find-file tumme-db-file)) | 2087 | (setq buf (find-file tumme-db-file)) |
| 2099 | (goto-char (point-min)) | 2088 | (goto-char (point-min)) |
| 2100 | (if (search-forward-regexp | 2089 | (when (search-forward-regexp |
| 2101 | (format "^%s" base-name) nil t) | 2090 | (format "^%s" base-name) nil t) |
| 2102 | (progn | 2091 | (end-of-line) |
| 2103 | (end-of-line) | 2092 | (setq end (point)) |
| 2104 | (setq end (point)) | 2093 | (beginning-of-line) |
| 2105 | (beginning-of-line) | 2094 | (cond ((search-forward ";comment:" end t) |
| 2106 | (cond ((search-forward ";comment:" end t) | 2095 | (setq comment-beg (point)) |
| 2107 | (setq comment-beg (point)) | 2096 | (if (search-forward ";" end t) |
| 2108 | (if (search-forward ";" end t) | 2097 | (setq comment-end (- (point) 1)) |
| 2109 | (setq comment-end (- (point) 1)) | 2098 | (setq comment-end end)) |
| 2110 | (setq comment-end end)) | 2099 | (setq comment (buffer-substring |
| 2111 | (setq comment (buffer-substring | 2100 | comment-beg comment-end))))) |
| 2112 | comment-beg comment-end)))))) | ||
| 2113 | (kill-buffer buf) | 2101 | (kill-buffer buf) |
| 2114 | comment))) | 2102 | comment))) |
| 2115 | 2103 | ||