From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH 1/3] org-datetree.el: Code cleanup. Date: Wed, 02 Sep 2015 21:48:07 +0200 Message-ID: <87si6w8ux4.fsf@nicolasgoaziou.fr> References: <3775628.BqEO9YxpYl@descartes> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXDzM-0007PN-1j for emacs-orgmode@gnu.org; Wed, 02 Sep 2015 15:46:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZXDzK-0002pQ-Qe for emacs-orgmode@gnu.org; Wed, 02 Sep 2015 15:46:31 -0400 Received: from relay4-d.mail.gandi.net ([2001:4b98:c:538::196]:49358) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXDzK-0002pJ-5h for emacs-orgmode@gnu.org; Wed, 02 Sep 2015 15:46:30 -0400 In-Reply-To: <3775628.BqEO9YxpYl@descartes> (=?utf-8?Q?=22R=C3=BCdiger?= Sonderfeld"'s message of "Wed, 02 Sep 2015 09:06:04 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: =?utf-8?Q?R=C3=BCdiger?= Sonderfeld Cc: emacs-orgmode@gnu.org Hello, R=C3=BCdiger Sonderfeld writes: > * lisp/org-datetree.el (org-datetree--find-create): New function. > (org-datetree-find-year-create, org-datetree-find-month-create, > org-datetree-find-day-create): Removed functions > (org-datetree-find-date-create): Use `org-datetree--find-create' instead > of removed functions. Use calendar extract functions. > (org-datetree-insert-line): Do more formatting in `format-time-string' > since we call it anyway > * testing/lisp/test-org-datetree.el (test-org-datetree/find-date-create): > Test if new entries are put at the right place. Thank you. Minor comments follow. > --- > lisp/org-datetree.el | 77 +++++++++------------------------= ------ > testing/lisp/test-org-datetree.el | 9 +++++ > 2 files changed, 27 insertions(+), 59 deletions(-) > > diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el > index a97a9d0..3620bbd 100644 > --- a/lisp/org-datetree.el > +++ b/lisp/org-datetree.el > @@ -64,67 +64,30 @@ (defun org-datetree-find-date-create (date &optional = keep-restriction) > (org-get-valid-level (org-current-level) 1)) > (org-narrow-to-subtree))) > (goto-char (point-min)) > - (let ((year (nth 2 date)) > - (month (car date)) > - (day (nth 1 date))) > - (org-datetree-find-year-create year) > - (org-datetree-find-month-create year month) > - (org-datetree-find-day-create year month day)))) > - > -(defun org-datetree-find-year-create (year) > - "Find the YEAR datetree or create it." > - (let ((re "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\\([ \t]:[[:alnum= :]:_@#%]+:\\)?\\s-*$\\)") > + (let ((year (calendar-extract-year date)) > + (month (calendar-extract-month date)) > + (day (calendar-extract-day date))) > + (org-datetree--find-create "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\= s-*?\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)" > + year) > + (org-datetree--find-create "^\\*+[ \t]+%d-\\([01][0-9]\\) \\w+$" > + year month) > + (org-datetree--find-create "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \= \w+$" > + year month day)))) > + > +(defun org-datetree--find-create (regex year &optional month day) > + "Find the datetree matched by REGEX for YEAR, MONTH, or DAY." You should add you are expecting something special in matching group 1, for comparison. > + (let ((re (format regex year month day)) > match) > (goto-char (point-min)) > (while (and (setq match (re-search-forward re nil t)) > (goto-char (match-beginning 1)) > - (< (string-to-number (match-string 1)) year))) > + (< (string-to-number (match-string 1)) (or day month year)))) > (cond > ((not match) > (goto-char (point-max)) > - (or (bolp) (newline)) > - (org-datetree-insert-line year)) > - ((=3D (string-to-number (match-string 1)) year) > - (goto-char (point-at-bol))) > - (t > - (beginning-of-line 1) > - (org-datetree-insert-line year))))) > - > -(defun org-datetree-find-month-create (year month) > - "Find the datetree for YEAR and MONTH or create it." > - (org-narrow-to-subtree) > - (let ((re (format "^\\*+[ \t]+%d-\\([01][0-9]\\) \\w+$" year)) > - match) > - (goto-char (point-min)) > - (while (and (setq match (re-search-forward re nil t)) > - (goto-char (match-beginning 1)) > - (< (string-to-number (match-string 1)) month))) > - (cond > - ((not match) > - (goto-char (point-max)) > - (or (bolp) (newline)) > - (org-datetree-insert-line year month)) > - ((=3D (string-to-number (match-string 1)) month) > - (goto-char (point-at-bol))) > - (t > - (beginning-of-line 1) > - (org-datetree-insert-line year month))))) > - > -(defun org-datetree-find-day-create (year month day) > - "Find the datetree for YEAR, MONTH and DAY or create it." > - (org-narrow-to-subtree) > - (let ((re (format "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" year mo= nth)) > - match) > - (goto-char (point-min)) > - (while (and (setq match (re-search-forward re nil t)) > - (goto-char (match-beginning 1)) > - (< (string-to-number (match-string 1)) day))) > - (cond > - ((not match) > - (goto-char (point-max)) > - (or (bolp) (newline)) > + (unless (bolp) (newline)) While you're at it: (unless (bolp) (insert "\n")) > diff --git a/testing/lisp/test-org-datetree.el b/testing/lisp/test-org-da= tetree.el > index d500130..0135ab9 100644 > --- a/testing/lisp/test-org-datetree.el > +++ b/testing/lisp/test-org-datetree.el > @@ -55,6 +55,15 @@ (ert-deftest test-org-datetree/find-date-create () > (let ((org-datetree-add-timestamp nil)) > (org-datetree-find-date-create '(3 29 2012))) > (org-trim (buffer-string))))) > + ;; Sort new entry in right place Missing full stop. Regards, --=20 Nicolas Goaziou