1

我在 Wanderlust 中的电子邮件的标题如下所示:

Date:  Wed, 23 Oct 2013 12:18:15 -0700

我想修改我的print-to-pdf函数的开头,以便它在当前缓冲区中搜索它找到的第一个日期(通常是缓冲区的第一行)并将其转换为pdf-file-name如下所示的提议:

10_23_2013.pdf

我的函数的开头print-to-pdf如下所示:

(defun print-to-pdf (pdf-file-name)
  "Print the current buffer to the given file."
  (interactive (list
    (ns-read-file-name "Write PDF file: " "/Users/HOME/.0.data/" nil ".pdf")))
  (cond (
    (not (equal pdf-file-name nil))

  ***

任何人都可以想出一种方法来搜索日期并将其变成提议pdf-file-name吗?


编辑:这是我通过 grepping Wanderlust 代码找到的一些日期字符串函数:

(defun wl-make-date-string ()
  (let ((system-time-locale "C"))
    (format-time-string "%a, %d %b %Y %T %z")))

(defsubst wl-get-date-iso8601 (date)
  (or (get-text-property 0 'wl-date date)
      (let* ((d1 (timezone-fix-time date nil nil))
         (time (format "%04d%02d%02dT%02d%02d%02d"
               (aref d1 0) (aref d1 1) (aref d1 2)
               (aref d1 3) (aref d1 4) (aref d1 5))))
    (put-text-property 0 1 'wl-date time date)
    time)))

(defun wl-make-date-string ()
  (let ((s (current-time-string)))
    (string-match "\\`\\([A-Z][a-z][a-z]\\) +[A-Z][a-z][a-z] +[0-9][0-9]? *[0-9][0-9]?:[0-9][0-9]:[0-9][0-9] *[0-9]?[0-9]?[0-9][0-9]"
          s)
    (concat (wl-match-string 1 s) ", "
        (timezone-make-date-arpa-standard s (current-time-zone)))))

(defun wl-date-iso8601 (date)
  "Convert the DATE to YYMMDDTHHMMSS."
  (condition-case ()
      (wl-get-date-iso8601 date)
    (error "")))
4

1 回答 1

2

这是功能。如果你能找到一种方法来提取Wed, 23 Oct 2013 12:18:15 -0700,它就会产生 10_23_2013.pdf

(defun transform-date (s &optional shift)
  (let ((time (apply 'encode-time
                     (org-read-date-analyze
                      s nil
                      (decode-time (current-time))))))
    (when shift
      (setq time (time-add time (days-to-time shift))))
    (format-time-string "%m_%d_%Y.pdf" time)))

这是一个简单的日期查找器:

(defun find-and-transform ()
  (goto-char (point-min))
  (when (re-search-forward "Date: \\([^:]*?\\)[0-9]+:")
    (transform-date
     (match-string-no-properties 1)))) 
于 2013-10-26T18:35:46.580 回答