aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Berman2017-08-01 14:17:44 +0200
committerStephen Berman2017-08-01 14:17:44 +0200
commit4ddc5645606478725ae0c27c85aa3c5dca6360d6 (patch)
tree5f1edc45e51176d963f8c2d4e25db7a95db9b7dd
parentcb764acce7c572aba093fa61baf26d5f5babcdca (diff)
downloademacs-4ddc5645606478725ae0c27c85aa3c5dca6360d6.tar.gz
emacs-4ddc5645606478725ae0c27c85aa3c5dca6360d6.zip
Update todo-mode defcustoms in a less hideous way
* lisp/calendar/todo-mode.el (todo-reevaluate-filelist-defcustoms) (todo-reevaluate-default-file-defcustom) (todo-reevaluate-category-completions-files-defcustom) (todo-reevaluate-filter-files-defcustom): Delete these functions. (todo-update-filelist-defcustoms): New function. This replaces todo-reevaluate-filelist-defcustoms, using the 'custom-type' property instead of re-evaluating the defcustoms. (todo-add-file, todo-rename-file, todo-delete-file) (todo-delete-category, todo-move-category) (todo-convert-legacy-files, todo-check-file): Replace call of todo-reevaluate-filelist-defcustoms by todo-update-filelist-defcustoms. (todo-show, todo-category-completions): Replace call of todo-reevaluate-* function by use of 'custom-type' property.
-rw-r--r--lisp/calendar/todo-mode.el84
1 files changed, 20 insertions, 64 deletions
diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el
index 1cb01e1ed9e..e39fee5bfa1 100644
--- a/lisp/calendar/todo-mode.el
+++ b/lisp/calendar/todo-mode.el
@@ -701,7 +701,8 @@ and done items are always shown on visiting a category."
701 ;; We just initialized the first todo file, so make it the default. 701 ;; We just initialized the first todo file, so make it the default.
702 (setq todo-default-todo-file (todo-short-file-name file) 702 (setq todo-default-todo-file (todo-short-file-name file)
703 first-file t) 703 first-file t)
704 (todo-reevaluate-default-file-defcustom)) 704 (put 'todo-default-todo-file 'custom-type
705 `(radio ,@(todo--files-type-list))))
705 (unless (member file todo-visited) 706 (unless (member file todo-visited)
706 ;; Can't setq t-c-t-f here, otherwise wrong file shown when 707 ;; Can't setq t-c-t-f here, otherwise wrong file shown when
707 ;; todo-show is called from todo-show-categories-table. 708 ;; todo-show is called from todo-show-categories-table.
@@ -780,7 +781,8 @@ and done items are always shown on visiting a category."
780 (when first-file 781 (when first-file
781 (setq todo-default-todo-file nil 782 (setq todo-default-todo-file nil
782 todo-current-todo-file nil) 783 todo-current-todo-file nil)
783 (todo-reevaluate-default-file-defcustom)) 784 (put 'todo-default-todo-file 'custom-type
785 `(radio ,@(todo--files-type-list))))
784 (kill-buffer) 786 (kill-buffer)
785 (keyboard-quit))))) 787 (keyboard-quit)))))
786 (save-excursion (todo-category-select)) 788 (save-excursion (todo-category-select))
@@ -1102,7 +1104,7 @@ Noninteractively, return the name of the new file."
1102 (write-region (point-min) (point-max) file nil 'nomessage nil t) 1104 (write-region (point-min) (point-max) file nil 'nomessage nil t)
1103 (kill-buffer file)) 1105 (kill-buffer file))
1104 (setq todo-files (funcall todo-files-function)) 1106 (setq todo-files (funcall todo-files-function))
1105 (todo-reevaluate-filelist-defcustoms) 1107 (todo-update-filelist-defcustoms)
1106 (if (called-interactively-p 'any) 1108 (if (called-interactively-p 'any)
1107 (progn 1109 (progn
1108 (set-window-buffer (selected-window) 1110 (set-window-buffer (selected-window)
@@ -1156,7 +1158,7 @@ these files, also rename them accordingly."
1156 (setq todo-default-todo-file snname)) 1158 (setq todo-default-todo-file snname))
1157 (when (string= todo-global-current-todo-file oname) 1159 (when (string= todo-global-current-todo-file oname)
1158 (setq todo-global-current-todo-file nname)) 1160 (setq todo-global-current-todo-file nname))
1159 (todo-reevaluate-filelist-defcustoms))) 1161 (todo-update-filelist-defcustoms)))
1160 1162
1161(defun todo-delete-file () 1163(defun todo-delete-file ()
1162 "Delete the current todo, archive or filtered items file. 1164 "Delete the current todo, archive or filtered items file.
@@ -1217,7 +1219,7 @@ visiting the deleted files."
1217 (when (or (string= file1 todo-global-current-todo-file) 1219 (when (or (string= file1 todo-global-current-todo-file)
1218 (and delete2 (string= file2 todo-global-current-todo-file))) 1220 (and delete2 (string= file2 todo-global-current-todo-file)))
1219 (setq todo-global-current-todo-file nil)) 1221 (setq todo-global-current-todo-file nil))
1220 (todo-reevaluate-filelist-defcustoms) 1222 (todo-update-filelist-defcustoms)
1221 (message (concat (cond (todo "Todo") (archive "Archive")) " file \"%s\" " 1223 (message (concat (cond (todo "Todo") (archive "Archive")) " file \"%s\" "
1222 (when delete2 1224 (when delete2
1223 (concat "and its " 1225 (concat "and its "
@@ -1387,7 +1389,7 @@ todo or done items."
1387 (if (= (length todo-categories) 1) 1389 (if (= (length todo-categories) 1)
1388 ;; If deleted category was the only one, delete the file. 1390 ;; If deleted category was the only one, delete the file.
1389 (progn 1391 (progn
1390 (todo-reevaluate-filelist-defcustoms) 1392 (todo-update-filelist-defcustoms)
1391 ;; Skip confirming killing the archive buffer if it has been 1393 ;; Skip confirming killing the archive buffer if it has been
1392 ;; modified and not saved. 1394 ;; modified and not saved.
1393 (set-buffer-modified-p nil) 1395 (set-buffer-modified-p nil)
@@ -1430,7 +1432,7 @@ the archive of the file moved to, creating it if it does not exist."
1430 (write-region (point-min) (point-max) nfile nil 'nomessage nil t) 1432 (write-region (point-min) (point-max) nfile nil 'nomessage nil t)
1431 (kill-buffer nfile)) 1433 (kill-buffer nfile))
1432 (setq todo-files (funcall todo-files-function)) 1434 (setq todo-files (funcall todo-files-function))
1433 (todo-reevaluate-filelist-defcustoms)) 1435 (todo-update-filelist-defcustoms))
1434 (dolist (buf buffers) 1436 (dolist (buf buffers)
1435 ;; Make sure archive file is in Todo Archive mode so that 1437 ;; Make sure archive file is in Todo Archive mode so that
1436 ;; todo-categories has correct value. 1438 ;; todo-categories has correct value.
@@ -1524,7 +1526,7 @@ the archive of the file moved to, creating it if it does not exist."
1524 (delete-file todo-current-todo-file) 1526 (delete-file todo-current-todo-file)
1525 (kill-buffer) 1527 (kill-buffer)
1526 (when (member todo-current-todo-file todo-files) 1528 (when (member todo-current-todo-file todo-files)
1527 (todo-reevaluate-filelist-defcustoms))) 1529 (todo-update-filelist-defcustoms)))
1528 (setq todo-categories (delete (assoc cat todo-categories) 1530 (setq todo-categories (delete (assoc cat todo-categories)
1529 todo-categories)) 1531 todo-categories))
1530 (todo-update-categories-sexp) 1532 (todo-update-categories-sexp)
@@ -4799,7 +4801,7 @@ name in `todo-directory'. See also the documentation string of
4799 (prin1 sexp (current-buffer))) 4801 (prin1 sexp (current-buffer)))
4800 (write-region (point-min) (point-max) file nil 'nomessage)) 4802 (write-region (point-min) (point-max) file nil 'nomessage))
4801 (setq todo-archives (funcall todo-files-function t))) 4803 (setq todo-archives (funcall todo-files-function t)))
4802 (todo-reevaluate-filelist-defcustoms) 4804 (todo-update-filelist-defcustoms)
4803 (when (y-or-n-p (concat "Format conversion done; do you want to " 4805 (when (y-or-n-p (concat "Format conversion done; do you want to "
4804 "visit the converted file now? ")) 4806 "visit the converted file now? "))
4805 (setq todo-current-todo-file file) 4807 (setq todo-current-todo-file file)
@@ -4863,7 +4865,7 @@ buffer, clean up the state and return nil."
4863 (member todo-default-todo-file files)) 4865 (member todo-default-todo-file files))
4864 (setq todo-default-todo-file (todo-short-file-name 4866 (setq todo-default-todo-file (todo-short-file-name
4865 (car todo-files)))) 4867 (car todo-files))))
4866 (todo-reevaluate-filelist-defcustoms) 4868 (todo-update-filelist-defcustoms)
4867 (when buf (kill-buffer buf)) 4869 (when buf (kill-buffer buf))
4868 nil))))) 4870 nil)))))
4869 4871
@@ -5749,7 +5751,8 @@ have been removed."
5749 " been deleted and removed from\n" 5751 " been deleted and removed from\n"
5750 "the list of category completion files") 5752 "the list of category completion files")
5751 names)) 5753 names))
5752 (todo-reevaluate-category-completions-files-defcustom) 5754 (put 'todo-category-completions-files 'custom-type
5755 `(set ,@(todo--files-type-list)))
5753 (custom-set-default 'todo-category-completions-files 5756 (custom-set-default 'todo-category-completions-files
5754 (symbol-value 'todo-category-completions-files)) 5757 (symbol-value 'todo-category-completions-files))
5755 (sleep-for 1.5))) 5758 (sleep-for 1.5)))
@@ -6249,59 +6252,12 @@ the empty string (i.e., no time string)."
6249 (hl-line-mode 1) 6252 (hl-line-mode 1)
6250 (hl-line-mode -1))))))))) 6253 (hl-line-mode -1)))))))))
6251 6254
6252(defun todo-reevaluate-filelist-defcustoms () 6255(defun todo-update-filelist-defcustoms ()
6253 "Reevaluate defcustoms that provide choice list of todo files." 6256 "Update defcustoms that provide choice list of todo files."
6254 ;; FIXME: This is hideous! I don't know enough about Custom to 6257 (put 'todo-default-todo-file 'custom-type `(radio ,@(todo--files-type-list)))
6255 ;; offer something better, but please ask on emacs-devel! 6258 (put 'todo-category-completions-files 'custom-type
6256 (custom-set-default 'todo-default-todo-file 6259 `(set ,@(todo--files-type-list)))
6257 (symbol-value 'todo-default-todo-file)) 6260 (put 'todo-filter-files 'custom-type `(set ,@(todo--files-type-list))))
6258 (todo-reevaluate-default-file-defcustom)
6259 (custom-set-default 'todo-filter-files (symbol-value 'todo-filter-files))
6260 (todo-reevaluate-filter-files-defcustom)
6261 (custom-set-default 'todo-category-completions-files
6262 (symbol-value 'todo-category-completions-files))
6263 (todo-reevaluate-category-completions-files-defcustom))
6264
6265(defun todo-reevaluate-default-file-defcustom ()
6266 "Reevaluate defcustom of `todo-default-todo-file'.
6267Called after adding or deleting a todo file. If the value of
6268`todo-default-todo-file' before calling this function was
6269associated with an existing file, keep that value."
6270 ;; FIXME: This is hideous! I don't know enough about Custom to
6271 ;; offer something better, but please ask on emacs-devel!
6272 ;; (let ((curval todo-default-todo-file))
6273 (eval
6274 (defcustom todo-default-todo-file (todo-short-file-name
6275 (car (funcall todo-files-function)))
6276 "Todo file visited by first session invocation of `todo-show'."
6277 :type (when todo-files
6278 `(radio ,@(todo--files-type-list)))
6279 :group 'todo))
6280 ;; (when (and curval (file-exists-p (todo-absolute-file-name curval)))
6281 ;; (custom-set-default 'todo-default-todo-file curval)
6282 ;; ;; (custom-reevaluate-setting 'todo-default-todo-file)
6283 ;; )))
6284 )
6285
6286(defun todo-reevaluate-category-completions-files-defcustom ()
6287 "Reevaluate defcustom of `todo-category-completions-files'.
6288Called after adding or deleting a todo file."
6289 ;; FIXME: This is hideous! I don't know enough about Custom to
6290 ;; offer something better, but please ask on emacs-devel!
6291 (eval (defcustom todo-category-completions-files nil
6292 "List of files for building `todo-read-category' completions."
6293 :type `(set ,@(todo--files-type-list))
6294 :group 'todo)))
6295
6296(defun todo-reevaluate-filter-files-defcustom ()
6297 "Reevaluate defcustom of `todo-filter-files'.
6298Called after adding or deleting a todo file."
6299 ;; FIXME: This is hideous! I don't know enough about Custom to
6300 ;; offer something better, but please ask on emacs-devel!
6301 (eval (defcustom todo-filter-files nil
6302 "List of files for multifile item filtering."
6303 :type `(set ,@(todo--files-type-list))
6304 :group 'todo)))
6305 6261
6306;; ----------------------------------------------------------------------------- 6262;; -----------------------------------------------------------------------------
6307;;; Font locking 6263;;; Font locking