Commit a8f4bb83 authored by Stephen Berman's avatar Stephen Berman
Browse files

* diary-lib.el (diary-goto-entry-function): New variable.

(diary-entry): Use it in the action of this button type instead of
diary-goto-entry.

* todos.el (todos-diary-goto-entry): Add item locating code from
diary-goto-entry.  Add it at the top-level to override the latter
function.
(todos-powerset): Use definition by Wolfgang Jenkner, posted at
http://lists.gnu.org/archive/html/emacs-devel/2013-06/msg00423.html.
parent bd358779
2013-06-18 Stephen Berman <stephen.berman@gmx.net>
* todos.el (todos-diary-goto-entry): Add item locating code from
diary-goto-entry. Add it at the top-level to override the latter
function.
(todos-powerset): Use definition by Wolfgang Jenkner, posted at
http://lists.gnu.org/archive/html/emacs-devel/2013-06/msg00423.html.
* diary-lib.el (diary-goto-entry-function): New variable.
(diary-entry): Use it in the action of this button type instead of
diary-goto-entry.
2013-06-09 Stephen Berman <stephen.berman@gmx.net> 2013-06-09 Stephen Berman <stephen.berman@gmx.net>
* todos.el (todos-edit-done-item-comment): Rename from * todos.el (todos-edit-done-item-comment): Rename from
......
...@@ -1032,7 +1032,14 @@ in the mode line. This is an option for `diary-display-function'." ...@@ -1032,7 +1032,14 @@ in the mode line. This is an option for `diary-display-function'."
(define-obsolete-function-alias 'simple-diary-display (define-obsolete-function-alias 'simple-diary-display
'diary-simple-display "23.1") 'diary-simple-display "23.1")
(define-button-type 'diary-entry 'action #'diary-goto-entry (defvar diary-goto-entry-function 'diary-goto-entry
"Function called to jump to a diary entry.
Modes that require special handling of the included file
containing the diary entry can assign a suitable function to this
variable.")
(define-button-type 'diary-entry
'action (lambda (button) (funcall diary-goto-entry-function button))
'face 'diary-button 'help-echo "Find this diary entry" 'face 'diary-button 'help-echo "Find this diary entry"
'follow-link t) 'follow-link t)
......
...@@ -5005,16 +5005,39 @@ empty line above the done items separator." ...@@ -5005,16 +5005,39 @@ empty line above the done items separator."
(todos-item-start) (todos-item-start)
(not (looking-at (regexp-quote todos-nondiary-start)))))) (not (looking-at (regexp-quote todos-nondiary-start))))))
(defun todos-diary-goto-entry () ;; This duplicates the item locating code from diary-goto-entry, but
"Jump to todo item included in Fancy Diary display. ;; without the marker code, to test whether the latter is dispensible.
Helper function for `diary-goto-entry'." ;; If it is, diary-goto-entry can be simplified. The code duplication
(when (eq major-mode 'todos-mode) ;; here can also be eliminated, leaving only the widening and category
(let ((opoint (point))) ;; selection, and instead of :override advice :around can be used.
(re-search-backward (concat "^" (regexp-quote todos-category-beg)
"\\(.*\\)\n") nil t) (defun todos-diary-goto-entry (button)
(todos-category-number (match-string 1)) "Jump to the diary entry for the BUTTON at point.
(todos-category-select) If the entry is a todo item, display its category properly.
(goto-char opoint)))) Overrides `diary-goto-entry'."
;; Locate the diary item in its source file.
(let* ((locator (button-get button 'locator))
(file (cadr locator))
(date (regexp-quote (nth 2 locator)))
(content (regexp-quote (nth 3 locator))))
(if (not (and (file-exists-p file)
(find-file-other-window file)))
(message "Unable to locate this diary entry")
(when (eq major-mode 'todos-mode) (widen))
(goto-char (point-min))
(when (re-search-forward (format "%s.*\\(%s\\)" date content) nil t)
(goto-char (match-beginning 1)))
;; If it's a todo item, determine its category and display the
;; category properly.
(when (eq major-mode 'todos-mode)
(let ((opoint (point)))
(re-search-backward (concat "^" (regexp-quote todos-category-beg)
"\\(.*\\)\n") nil t)
(todos-category-number (match-string 1))
(todos-category-select)
(goto-char opoint))))))
(add-function :override diary-goto-entry-function #'todos-diary-goto-entry)
(defun todos-done-item-p () (defun todos-done-item-p ()
"Return non-nil if item at point is a done item." "Return non-nil if item at point is a done item."
...@@ -5146,41 +5169,15 @@ of each other." ...@@ -5146,41 +5169,15 @@ of each other."
;;; Utilities for generating item insertion commands and key bindings ;;; Utilities for generating item insertion commands and key bindings
;; ----------------------------------------------------------------------------- ;; -----------------------------------------------------------------------------
;; These two powerset definitions are adaptations of code published at ;; Wolfgang Jenkner posted this powerset definition to emacs-devel
;; http://rosettacode.org, whose content is licensed under GFDL 1.2. ;; (http://lists.gnu.org/archive/html/emacs-devel/2013-06/msg00423.html)
;; The recursive definition is a slight reformulation of ;; and kindly gave me permission to use it.
;; http://rosettacode.org/wiki/Power_set#Common_Lisp. The iterative
;; definition is my Elisp implementation of
;; http://rosettacode.org/wiki/Power_set#C. Can either of these be
;; included in Emacs, or is there no need to concerned about copyright
;; here?
;; (defun todos-powerset (list)
;; "Return the powerset of LIST."
;; (cond ((null list)
;; (list nil))
;; (t
;; (let ((recur (todos-powerset-recursive (cdr list)))
;; pset)
;; (dolist (elt recur pset)
;; (push (cons (car list) elt) pset))
;; (append pset recur)))))
(defun todos-powerset (list) (defun todos-powerset (list)
"Return the powerset of LIST." "Return the powerset of LIST."
(let ((card (expt 2 (length list))) (let ((powerset (list nil)))
pset elt) (dolist (elt list (mapcar 'reverse powerset))
(dotimes (n card) (nconc powerset (mapcar (apply-partially 'cons elt) powerset)))))
(let ((i n)
(l list))
(while (not (zerop i))
(let ((arg (pop l)))
(when (cl-oddp i)
(setq elt (append elt (list arg))))
(setq i (/ i 2))))
(setq pset (append pset (list elt)))
(setq elt nil)))
pset))
(defun todos-gen-arglists (arglist) (defun todos-gen-arglists (arglist)
"Return list of lists of non-nil atoms produced from ARGLIST. "Return list of lists of non-nil atoms produced from ARGLIST.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment