-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgentoo-newsitem-mode.el
More file actions
147 lines (123 loc) · 4.5 KB
/
gentoo-newsitem-mode.el
File metadata and controls
147 lines (123 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
;;; gentoo-newsitem-mode.el --- edit Gentoo news items -*-lexical-binding:t-*-
;; Copyright 2009-2026 Gentoo Authors
;; Author: Ulrich Müller <ulm@gentoo.org>
;; Maintainer: <emacs@gentoo.org>
;; Keywords: text
;; This file is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 2 of the License, or
;; (at your option) any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Minimum Emacs version:
;; GNU Emacs 26.3
;; XEmacs 21.5.35
;;; Code:
(require 'font-lock)
(require 'easymenu)
(require 'skeleton)
(require 'ebuild-mode)
(defvar gentoo-newsitem-font-lock-keywords
`((,(lambda (limit)
(gentoo-newsitem-search-header
(eval-when-compile
(concat "^"
(regexp-opt
'("Title" "Author" "Translator" "Content-Type" "Posted"
"Revision" "News-Item-Format" "Display-If-Installed"
"Display-If-Keyword" "Display-If-Profile")
t)
":"))
limit))
. font-lock-keyword-face)
;; Warn about overlong title
(,(lambda (limit)
(gentoo-newsitem-search-header
"^Title:[ \t]*.\\{50\\}\\(.*\\)" limit))
1 font-lock-warning-face t))
"Expressions to highlight in Gentoo newsitem mode.")
(defvar gentoo-newsitem-format-list
'("1.0" "2.0")
"List of news item formats defined by GLEP 42.")
;; suppress byte-compiler warning in XEmacs
(defvar gentoo-newsitem-mode-menu)
;;;###autoload
(define-derived-mode gentoo-newsitem-mode text-mode "Newsitem"
"Major mode for Gentoo GLEP 42 news items."
(if (featurep 'xemacs)
(easy-menu-add gentoo-newsitem-mode-menu))
(setq fill-column 72))
(defun gentoo-newsitem-search-header (regexp limit)
"Like `re-search-forward' but restricted to the header.
Search forward from point for regular expression REGEXP.
Buffer position LIMIT limits the search."
(let ((bound (save-excursion
(goto-char (point-min))
(re-search-forward "^$" limit 'move)
(point))))
(if (>= bound (point))
(re-search-forward regexp bound t))))
(defun gentoo-newsitem-add-font-lock ()
"Add `gentoo-newsitem-mode' font-lock keywords for the current buffer."
(font-lock-add-keywords nil gentoo-newsitem-font-lock-keywords))
(add-hook 'gentoo-newsitem-mode-hook #'gentoo-newsitem-add-font-lock)
(define-skeleton gentoo-newsitem-insert-skeleton
"Insert a skeleton for a Gentoo GLEP 42 news item."
nil
"Title: " (skeleton-read "Title: ") "\n"
"Author: " (skeleton-read
"Author's real name and e-mail address: "
(concat ebuild-mode-full-name
" <" ebuild-mode-mail-address ">"))
"\n"
((skeleton-read "Further author (null string to terminate): ")
"Author: " str "\n")
((skeleton-read "Translator (null string to terminate): ")
"Translator: " str "\n")
;;@ ; not supported in XEmacs 21.5
(progn
(setq v2 (point-marker))
nil)
"Posted: " (skeleton-read "Date of posting: "
(format-time-string "%Y-%m-%d" nil t))
"\n"
"Revision: 1\n"
"News-Item-Format: "
(setq v1 (completing-read
"News-Item-Format: "
(mapcar #'list gentoo-newsitem-format-list) nil 'confirm
nil nil (car (last gentoo-newsitem-format-list))))
"\n"
(if (string-equal v1 "1.0")
(save-excursion
;;(goto-char (car skeleton-positions))
(goto-char v2)
(insert "Content-Type: text/plain\n")
nil))
((skeleton-read "Display-If-Installed: (null string to terminate): ")
"Display-If-Installed: " str "\n")
((skeleton-read "Display-If-Keyword: (null string to terminate): ")
"Display-If-Keyword: " str "\n")
((skeleton-read "Display-If-Profile: (null string to terminate): ")
"Display-If-Profile: " str "\n")
"\n")
(define-key gentoo-newsitem-mode-map
"\C-c\C-n" #'gentoo-newsitem-insert-skeleton)
(easy-menu-define gentoo-newsitem-mode-menu gentoo-newsitem-mode-map
"Menu for `gentoo-newsitem-mode'."
'("Newsitem"
["Insert skeleton" gentoo-newsitem-insert-skeleton]))
;;;###autoload
(add-to-list 'auto-mode-alist
'("/[0-9]\\{4\\}-[01][0-9]-[0-3][0-9]-.+\\.[a-z]\\{2\\}\\.txt\\'"
. gentoo-newsitem-mode))
(provide 'gentoo-newsitem-mode)
;; Local Variables:
;; coding: utf-8
;; End:
;;; gentoo-newsitem-mode.el ends here