Function: time-stamp-once

time-stamp-once is a byte-compiled function defined in time-stamp.el.gz.

Signature

(time-stamp-once START SEARCH-LIMIT TS-START TS-END TS-FORMAT FORMAT-LINES END-LINES)

Documentation

Update one time stamp. Internal routine called by time-stamp.

Returns the end point, which is where time-stamp begins the next search.

Source Code

;; Defined in /usr/src/emacs/lisp/time-stamp.el.gz
(defun time-stamp-once (start search-limit ts-start ts-end
			ts-format format-lines end-lines)
  "Update one time stamp.  Internal routine called by `time-stamp'.
Returns the end point, which is where `time-stamp' begins the next search."
  (let ((case-fold-search nil)
	(end nil)
        (advance-nudge 0)
	end-search-start
	(end-length nil))
    (save-excursion
      (save-restriction
	(widen)
	;; Find the location of the time stamp.
	(while (and (< (goto-char start) search-limit)
		    (not end)
		    (re-search-forward ts-start search-limit 'move))
          ;; Whether or not we find a template, we must
          ;; advance through the buffer.
          (setq advance-nudge (if (> (point) start) 0 1))
	  (setq start (point))
	  (if (not time-stamp-inserts-lines)
	      (forward-line format-lines))
	  (setq end-search-start (max start (point)))
	  (if (= (forward-line end-lines) 0)
	      (progn
	       (and (bolp) (backward-char))
	       (let ((line-end (min (point) search-limit)))
		 (if (>= line-end end-search-start)
		     (progn
		      (goto-char end-search-start)
		      (if (re-search-forward ts-end line-end t)
			  (progn
			    (setq end (match-beginning 0))
                            (setq end-length (- (match-end 0) end)))
                        (setq start (+ start advance-nudge)))))))))))
    (if end
	(progn
	  ;; do all warnings outside save-excursion
	  (cond
	   ((not time-stamp-active)
	    (if time-stamp-warn-inactive
                (time-stamp--message
                 "Warning: time-stamp-active is off; did not time-stamp buffer."))
            nil)
	   (t
	    (let ((new-time-stamp (time-stamp-string ts-format)))
	      (if (and (stringp new-time-stamp)
		       (not (string-equal (buffer-substring start end)
					  new-time-stamp)))
		  (save-excursion
		    (save-restriction
		      (widen)
		      (delete-region start end)
		      (goto-char start)
		      (insert-and-inherit new-time-stamp)
		      (setq end (point))
		      ;; remove any tabs used to format time stamp
		      (if (search-backward "\t" start t)
			  (progn
			    (untabify start end)
                            (setq end (point))))))))
            ;; return the location after this time stamp
            (+ end (max advance-nudge end-length))))))))