From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Re: master 4cc4344: ; Clarify and simplify time-stamp comments Date: Thu, 14 Oct 2021 16:19:19 +0200 Message-ID: <87lf2vwuxk.fsf@gnus.org> References: <20210926152519.29145.33@vcs0.savannah.gnu.org> <20210926152521.5401420A5E@vcs0.savannah.gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27370"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Stephen Gildea To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Oct 14 16:20:10 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mb1ab-0006oL-QN for ged-emacs-devel@m.gmane-mx.org; Thu, 14 Oct 2021 16:20:09 +0200 Original-Received: from localhost ([::1]:51512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mb1aa-0005oF-SU for ged-emacs-devel@m.gmane-mx.org; Thu, 14 Oct 2021 10:20:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mb1Zx-00053l-0e for emacs-devel@gnu.org; Thu, 14 Oct 2021 10:19:29 -0400 Original-Received: from quimby.gnus.org ([2a01:4f9:2b:f0f::2]:54428) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mb1Zu-00010L-Nw for emacs-devel@gnu.org; Thu, 14 Oct 2021 10:19:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=7m7Z5EZ+oeGNdhBAfEGQCiixkqsStGjsiBOGQLH0IwE=; b=SMX5kXnSMwcz1tx+m+KddiCG4M 5L9gArYza34cH3suAVVmlu+9hkQ6aull0lNflDq1iT88rU8oY0ElOki8SD5GN6tUphtq7suGfIQbJ 2n1eWH4Pe6sVqm+DR3T67zXSxgaLLg3vFl0jnXHUrgbykEwkxEdKMISnsObgTrPIQlIo=; Original-Received: from [84.212.220.105] (helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mb1Zn-0002XR-Ig; Thu, 14 Oct 2021 16:19:22 +0200 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAABGdBTUEAALGPC/xhBQAAACBj SFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAJFBMVEULCgshHh5QT08v Li+Pj4/Q0ND4+Pign55wcHCxsbE/Pj/////9TU4gAAAAAWJLR0QLH9fEwAAAAAd0SU1FB+UKDg4O Ed6fb3UAAAGvSURBVDjLrZJLT8JAEICnLZDiadGIHCsEordWItFbYyJnYkKRGyId4IbxdW2iEI8m RIz/1t3u7HZBuDmH7WS+eXQeAFpKmVRrpcwOVgaagQm4MAoEi2XGg2YgSQo1sK8RsfeWJSV7JcL+ 6xfiI8WoVC6Oj0W2OT5YWTXOVxPyqMeeCc6nulZ7Yvykg6HWbUwycGh6tYaZvgoNYKOvVHfKnxNd ZfGptMK9iJJ+RwkUda5FSMAKWKsDTqxAxOgpYhzxPCtqZW+qaC5CnAE0ZhLkhjosj6KjckeCoqgN KJ4yj2Bk4G4DMa20YouP3qMUFEmg99P1wKVBlEVD1ncK0uy2CaTse2ugA+uiUhU2gSqev9sA6e8y 6VD3DVAYSGCPjVG7SxqJGAQyyKsdiv29eATaCd+63LQTJTR2Acq8emOcbnAx4rUnCrhj4ToKwJmL wEZHAeDxkEPsIi7FLfkapBdTeca+uGm6JSYvJtFNOFGYfmVjjZEGSvXJ7YbslyqYRpHDW5HUOhXl TcA946eP9whVpAZwwU8H4yv4A8A6q9YYbAEbsgtY/wrYLhCUtiHH/wX511YbTcUDIgAAACV0RVh0 ZGF0ZTpjcmVhdGUAMjAyMS0xMC0xNFQxNDoxNDoxNyswMDowMLGadPoAAAAldEVYdGRhdGU6bW9k aWZ5ADIwMjEtMTAtMTRUMTQ6MTQ6MTcrMDA6MDDAx8xGAAAAAElFTkSuQmCC X-Now-Playing: Simian Mobile Disco's _#savefabric (10) (Mixed by Terry Francis)_: "Balloon Takes A Holiday" In-Reply-To: <20210926152521.5401420A5E@vcs0.savannah.gnu.org> (Stephen Gildea's message of "Sun, 26 Sep 2021 11:25:20 -0400 (EDT)") Received-SPF: pass client-ip=2a01:4f9:2b:f0f::2; envelope-from=larsi@gnus.org; helo=quimby.gnus.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:277031 Archived-At: --=-=-= Content-Type: text/plain stepheng+savannah@gildea.com (Stephen Gildea) writes: > ; Clarify and simplify time-stamp comments I'm going through some old stuff I've got stashed in my Emacs git tree, and I found something I was working on in 2019, but don't remember the status of. The main idea behind this patch (which no longer applies) is that we could rewrite `time-stamp-string-preprocess' to just use `format-spec'. I vaguely remember there being some corner case that `format-spec' didn't support yet, but you've simplified the time-spec syntax a bit meanwhile, so perhaps it's possible now. Anyway, I'm just including the patch below -- perhaps it can be used for inspiration, but if not, just disregard it. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=time-stamp.patch diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el index f423683852..8157abbb3c 100644 --- a/lisp/time-stamp.el +++ b/lisp/time-stamp.el @@ -36,6 +36,8 @@ ;;; Code: +(require 'format-spec) + (defgroup time-stamp nil "Maintain last change time stamps in files edited by Emacs." :group 'data @@ -413,192 +415,33 @@ time-stamp-string (defconst time-stamp-no-file "(no file)" "String to use when the buffer is not associated with a file.") -;;; FIXME This comment was written in 1996! -;;; time-stamp is transitioning to using the new, expanded capabilities -;;; of format-time-string. During the process, this function implements -;;; intermediate, compatible formats and complains about old, soon to -;;; be unsupported, formats. This function will get a lot (a LOT) shorter -;;; when the transition is complete and we can just pass most things -;;; straight through to format-time-string. -;;; At all times, all the formats recommended in the doc string -;;; of time-stamp-format will work not only in the current version of -;;; Emacs, but in all versions that have been released within the past -;;; two years. -;;; The : modifier is a temporary conversion feature used to resolve -;;; ambiguous formats--formats that are changing (over time) incompatibly. (defun time-stamp-string-preprocess (format &optional time) "Use a FORMAT to format date, time, file, and user information. Optional second argument TIME is only for testing. Implements non-time extensions to `format-time-string' and all `time-stamp-format' compatibility." - (let ((fmt-len (length format)) - (ind 0) - cur-char - (prev-char nil) - (result "") - field-width - field-result - alt-form change-case - (paren-level 0)) - (while (< ind fmt-len) - (setq cur-char (aref format ind)) - (setq - result - (concat result - (cond - ((eq cur-char ?%) - ;; eat any additional args to allow for future expansion - (setq alt-form nil change-case nil field-width "") - (while (progn - (setq ind (1+ ind)) - (setq cur-char (if (< ind fmt-len) - (aref format ind) - ?\0)) - (or (eq ?. cur-char) - (eq ?, cur-char) (eq ?: cur-char) (eq ?@ cur-char) - (eq ?- cur-char) (eq ?+ cur-char) (eq ?_ cur-char) - (eq ?\s cur-char) (eq ?# cur-char) (eq ?^ cur-char) - (and (eq ?\( cur-char) - (not (eq prev-char ?\\)) - (setq paren-level (1+ paren-level))) - (if (and (eq ?\) cur-char) - (not (eq prev-char ?\\)) - (> paren-level 0)) - (setq paren-level (1- paren-level)) - (and (> paren-level 0) - (< ind fmt-len))) - (if (and (<= ?0 cur-char) (>= ?9 cur-char)) - ;; get format width - (let ((field-index ind)) - (while (progn - (setq ind (1+ ind)) - (setq cur-char (if (< ind fmt-len) - (aref format ind) - ?\0)) - (and (<= ?0 cur-char) (>= ?9 cur-char)))) - (setq field-width (substring format field-index ind)) - (setq ind (1- ind)) - t)))) - (setq prev-char cur-char) - ;; some characters we actually use - (cond ((eq cur-char ?:) - (setq alt-form t)) - ((eq cur-char ?#) - (setq change-case t)))) - (setq field-result - (cond - ((eq cur-char ?%) - "%%") - ((eq cur-char ?a) ;day of week - (if change-case - (time-stamp--format "%#a" time) - (or alt-form (not (string-equal field-width "")) - (time-stamp-conv-warn "%a" "%:a")) - (if (and alt-form (not (string-equal field-width ""))) - "" ;discourage "%:3a" - (time-stamp--format "%A" time)))) - ((eq cur-char ?A) - (if alt-form - (time-stamp--format "%A" time) - (or change-case (not (string-equal field-width "")) - (time-stamp-conv-warn "%A" "%#A")) - (time-stamp--format "%#A" time))) - ((eq cur-char ?b) ;month name - (if change-case - (time-stamp--format "%#b" time) - (or alt-form (not (string-equal field-width "")) - (time-stamp-conv-warn "%b" "%:b")) - (if (and alt-form (not (string-equal field-width ""))) - "" ;discourage "%:3b" - (time-stamp--format "%B" time)))) - ((eq cur-char ?B) - (if alt-form - (time-stamp--format "%B" time) - (or change-case (not (string-equal field-width "")) - (time-stamp-conv-warn "%B" "%#B")) - (time-stamp--format "%#B" time))) - ((eq cur-char ?d) ;day of month, 1-31 - (time-stamp-do-number cur-char alt-form field-width time)) - ((eq cur-char ?H) ;hour, 0-23 - (time-stamp-do-number cur-char alt-form field-width time)) - ((eq cur-char ?I) ;hour, 1-12 - (time-stamp-do-number cur-char alt-form field-width time)) - ((eq cur-char ?m) ;month number, 1-12 - (time-stamp-do-number cur-char alt-form field-width time)) - ((eq cur-char ?M) ;minute, 0-59 - (time-stamp-do-number cur-char alt-form field-width time)) - ((eq cur-char ?p) ;am or pm - (or change-case - (time-stamp-conv-warn "%p" "%#p")) - (time-stamp--format "%#p" time)) - ((eq cur-char ?P) ;AM or PM - (time-stamp--format "%p" time)) - ((eq cur-char ?S) ;seconds, 00-60 - (time-stamp-do-number cur-char alt-form field-width time)) - ((eq cur-char ?w) ;weekday number, Sunday is 0 - (time-stamp--format "%w" time)) - ((eq cur-char ?y) ;year - (or alt-form (not (string-equal field-width "")) - (time-stamp-conv-warn "%y" "%:y")) - (string-to-number (time-stamp--format "%Y" time))) - ((eq cur-char ?Y) ;4-digit year, new style - (string-to-number (time-stamp--format "%Y" time))) - ((eq cur-char ?z) ;time zone lower case - (if change-case - "" ;discourage %z variations - (time-stamp--format "%#Z" time))) - ((eq cur-char ?Z) - (if change-case - (time-stamp--format "%#Z" time) - (time-stamp--format "%Z" time))) - ((eq cur-char ?f) ;buffer-file-name, base name only - (if buffer-file-name + (format-spec + format + `((?f . ;buffer-file-name, base name only + ,(if buffer-file-name (file-name-nondirectory buffer-file-name) time-stamp-no-file)) - ((eq cur-char ?F) ;buffer-file-name, full path - (or buffer-file-name + (?F . ;buffer-file-name, full path + ,(or buffer-file-name time-stamp-no-file)) - ((eq cur-char ?s) ;system name - (system-name)) - ((eq cur-char ?u) ;user name - (user-login-name)) - ((eq cur-char ?U) ;user full name - (user-full-name)) - ((eq cur-char ?l) ;logname (undocumented user name alt) - (user-login-name)) - ((eq cur-char ?L) ;(undocumented alt user full name) - (user-full-name)) - ((eq cur-char ?h) ;mail host name - (or mail-host-address (system-name))) - ((eq cur-char ?q) ;(undocumented unqual hostname) - (let ((qualname (system-name))) + (?s . ,(system-name)) ; system name + (?u . ,(user-login-name)) ;user name + (?U . ,(user-full-name)) ;user full name + (?l . ,(user-login-name)) ;logname (undocumented user name alt) + (?L . ,(user-full-name)) ;(undocumented alt user full name) + (?h . ,(or mail-host-address (system-name))) ;mail host name + (?q . ;(undocumented unqual hostname) + ,(let ((qualname (system-name))) (if (string-match "\\." qualname) (substring qualname 0 (match-beginning 0)) qualname))) - ((eq cur-char ?Q) ;(undocumented fully-qualified host) - (system-name)) - )) - (let ((padded-result - (format (format "%%%s%c" - field-width - (if (numberp field-result) ?d ?s)) - (or field-result "")))) - (let* ((initial-length (length padded-result)) - (desired-length (if (string-equal field-width "") - initial-length - (string-to-number field-width)))) - (if (> initial-length desired-length) - ;; truncate strings on right, years on left - (if (stringp field-result) - (substring padded-result 0 desired-length) - (if (eq cur-char ?y) - (substring padded-result (- desired-length)) - padded-result)) ;non-year numbers don't truncate - padded-result)))) - (t - (char-to-string cur-char))))) - (setq ind (1+ ind))) - result)) + (?Q , (system-name))) ;(undocumented fully-qualified host) + t)) (defun time-stamp-do-number (format-char alt-form field-width time) "Handle compatible FORMAT-CHAR where only default width/padding will change. --=-=-=--