Emacs 如何将(日-月-年)转换为(月-日-年)

Emacs 如何将(日-月-年)转换为(月-日-年),emacs,elisp,Emacs,Elisp,我在Wanderlust中的电子邮件标题如下所示: Date: Wed, 23 Oct 2013 12:18:15 -0700 10_23_2013.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/

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

Date:  Wed, 23 Oct 2013 12:18:15 -0700
10_23_2013.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))

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

Date:  Wed, 23 Oct 2013 12:18:15 -0700
10_23_2013.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))

  ***
my
print to pdf
函数的开头如下所示:

Date:  Wed, 23 Oct 2013 12:18:15 -0700
10_23_2013.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文件名


编辑:以下是我通过对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 "")))
这里是函数。 如果您能找到提取
Wed,2013年10月23日12:18:15-0700
的方法,它将生成
10\u 23\u 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月23日
=>
2013年10月23日
?如果可能的话,我还可以使用
向前搜索
来提取日期
2013年10月23日
(可能是365种可能性中的任何一种)然后将其转换为
10_23_2013
。如果输入字符串的格式非常固定,如
Date:Wed,2013年10月23日12:18:15-0700
,则可以。否则,您需要某种锚来定位日期。就像组织模式那样。我可以编写一个函数,映射日期:Wed,2013年10月23日12:18:15-0700=>
10\u 23\u 2013
。这就足够了吗?我将花一分钟的时间对Wanderlust的代码进行grep处理,以找到显示电子邮件缓冲区时打印的日期字符串,然后我将发布我找到的代码(这可能有助于查看生成的可能性)。仅供参考,当它不用于特殊用途时,它会更好(而且更简单)为匹配的对象生成一个更有针对性的regexp。e、 g.:
(定义我的日期regexp(concat(regexp opt'(“周一”“周二”“周三”“周四”“周五”“周六”“周日”),[0-9]\{1,2\\}(regexp opt'(“一月”“二月”“三月”“四月”“五月”“六月”“七月”“八月”“九月”“十月”“十一月”“十二月”)“[0-9]\\{4\\}”匹配表格的日期:%a,%d%b%Y(请参见“格式时间字符串”。