unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* A cleaning-up patch for parse-time.el
@ 2016-03-19  7:12 Marcin Borkowski
  2016-03-19  7:41 ` John Wiegley
  2016-03-25 15:24 ` Lars Magne Ingebrigtsen
  0 siblings, 2 replies; 10+ messages in thread
From: Marcin Borkowski @ 2016-03-19  7:12 UTC (permalink / raw)
  To: Emacs Developers

[-- Attachment #1: Type: text/plain, Size: 825 bytes --]

Hi Emacs Devs,

in my attempt to enhance Org-mode's date/time parsing, I found out that
I'll probably need to submit some modifications to `parse-time-string'.
While studying parse-time.el, I encountered some code whose purpose was
not obvious at the first glance, so I corrected it.  I attach a patch.
Is submitting such a patch a good idea?  (It does not introduce any new
features or bugfixes, just cleaning up: adding/expanding docstrings,
making one argument name better, adding a newline, and changing `not'
into `null'.)  How do I write a commit message for that?  (I went for
simplicity/terseness, since the diff speaks for itself.)

Thanks for your patience and best regards,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-the-parse-time-tokenize-more-readable.patch --]
[-- Type: text/x-patch, Size: 1995 bytes --]

From fa2524bd41641d18bad51ca0a99986102d900568 Mon Sep 17 00:00:00 2001
From: Marcin Borkowski <mbork@mbork.pl>
Date: Sat, 19 Mar 2016 08:05:17 +0100
Subject: [PATCH] Make the `parse-time-tokenize' more readable

* lisp/calendar/parse-time.el (parse-time-string-chars)
(parse-time-tokenize): Make code more readable
---
 lisp/calendar/parse-time.el | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/lisp/calendar/parse-time.el b/lisp/calendar/parse-time.el
index 6ba26a4..33e936c 100644
--- a/lisp/calendar/parse-time.el
+++ b/lisp/calendar/parse-time.el
@@ -40,15 +40,18 @@
 (defvar parse-time-elt)
 (defvar parse-time-val)
 
-(defsubst parse-time-string-chars (char)
-  (cond ((<= ?a char ?z) ?a)
-        ((<= ?0 char ?9) ?0)
-        ((eq char ?+) 1)
-        ((eq char ?-) -1)
-        ((eq char ?:) ?d)))
+(defsubst parse-time-string-chars (character)
+  "Classify CHARACTER for `parse-time-tokenize'."
+  (cond ((<= ?a character ?z) ?a)
+        ((<= ?0 character ?9) ?0)
+        ((eq character ?+) 1)
+        ((eq character ?-) -1)
+        ((eq character ?:) ?d)))
 
 (defun parse-time-tokenize (string)
-  "Tokenize STRING into substrings."
+  "Tokenize STRING into substrings.
+Each substring is a run of \"valid\" characters, i.e., lowercase
+letters, digits, plus or minus signs or colons."
   (let ((start nil)
 	(end (length string))
 	(all-digits nil)
@@ -57,9 +60,10 @@ parse-time-tokenize
 	(c nil))
     (while (< index end)
       (while (and (< index end)		;Skip invalid characters.
-		  (not (setq c (parse-time-string-chars (aref string index)))))
+		  (null (setq c (parse-time-string-chars (aref string index)))))
 	(cl-incf index))
-      (setq start index all-digits (eq c ?0))
+      (setq start index
+            all-digits (eq c ?0))
       (while (and (< (cl-incf index) end)	;Scan valid characters.
 		  (setq c (parse-time-string-chars (aref string index))))
 	(setq all-digits (and all-digits (eq c ?0))))
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-03-26 22:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-19  7:12 A cleaning-up patch for parse-time.el Marcin Borkowski
2016-03-19  7:41 ` John Wiegley
2016-03-19  7:49   ` Marcin Borkowski
2016-03-19 23:21     ` John Wiegley
2016-03-20 22:38       ` Michael Heerdegen
2016-03-21  0:12         ` Michael Heerdegen
2016-03-25 15:24 ` Lars Magne Ingebrigtsen
2016-03-25 16:27   ` Marcin Borkowski
2016-03-25 16:35     ` Lars Magne Ingebrigtsen
2016-03-26 22:16       ` John Wiegley

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).