diff options
author | Ulrich Müller <ulm@gentoo.org> | 2017-10-28 07:08:18 +0200 |
---|---|---|
committer | Ulrich Müller <ulm@gentoo.org> | 2017-10-28 07:08:18 +0200 |
commit | 24a79f6439c6036429b5f955542d2d35a96aa012 (patch) | |
tree | 3888f8700b90007e4bb7e65ea3569d5ec1241d95 /glep-mode.el | |
parent | Rename ebuild-mode customisation group to ebuild. (diff) | |
download | ebuild-mode-24a79f6439c6036429b5f955542d2d35a96aa012.tar.gz ebuild-mode-24a79f6439c6036429b5f955542d2d35a96aa012.tar.bz2 ebuild-mode-24a79f6439c6036429b5f955542d2d35a96aa012.zip |
Update the Last-Modified header when saving a GLEP.
* glep-mode.el (glep-mode-update-last-modified): New function,
updates the Last-Modified header when saving the file.
(glep): New customisation group.
(glep-mode-update-last-modified): New custom variable.
(glep-mode-last-modified-re): New variable.
(glep-mode-before-save): New function.
(glep-mode): Add glep-mode-before-save to write-contents-hook.
Diffstat (limited to 'glep-mode.el')
-rw-r--r-- | glep-mode.el | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/glep-mode.el b/glep-mode.el index 4c7f81b..4b18ad1 100644 --- a/glep-mode.el +++ b/glep-mode.el @@ -28,6 +28,15 @@ (require 'easymenu) (require 'skeleton) +(defgroup glep nil + "Major mode for Gentoo Linux Enhancement Proposals." + :group 'wp) + +(defcustom glep-mode-update-last-modified t + "If non-nil, update Last-Modified date before writing a file." + :type 'boolean + :group 'glep) + (defvar glep-mode-font-lock-keywords (eval-when-compile (concat "^" @@ -42,10 +51,34 @@ (defvar glep-mode-delim-re "^---$" "Regexp matching delimiters of the GLEP header.") +(defvar glep-mode-last-modified-re + "^Last-Modified:[ \t]+\\([0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9]\\)[ \t]*$" + "Regexp matching the Last-Modified header line.") + (defvar glep-mode-preamble-limit 2000 "Maximum length of GLEP preamble. For efficiency only. Unlimited if nil.") +(defun glep-mode-update-last-modified () + ;; Update Last-Modified date + (save-excursion + (goto-char (point-min)) + (let ((date (format-time-string "%Y-%m-%d" nil t)) + (case-fold-search nil)) + (and (re-search-forward glep-mode-last-modified-re + glep-mode-preamble-limit t) + (glep-mode-in-preamble-p (point)) + (not (string-equal date (match-string 1))) + (replace-match date t t nil 1))))) + +(defun glep-mode-before-save () + (when glep-mode-update-last-modified + (glep-mode-update-last-modified) + ;; call it only once per buffer + (set (make-local-variable 'glep-mode-update-last-modified) nil)) + ;; return nil, otherwise the file is presumed to be written + nil) + ;;;###autoload (define-derived-mode glep-mode rst-mode "GLEP" "Major mode for Gentoo Linux Enhancement Proposals." @@ -59,7 +92,8 @@ For efficiency only. Unlimited if nil.") (setq sentence-end-double-space t) (setq fill-column 70) (add-hook 'font-lock-extend-region-functions - 'glep-mode-font-lock-extend-region t)) + 'glep-mode-font-lock-extend-region t) + (add-hook 'write-contents-hooks 'glep-mode-before-save t t)) (add-hook 'glep-mode-hook |