1
;;; desktop-entry-mode.el --- freedesktop.org desktop entry editing
3
;; Copyright (C) 2003-2004, 2006-2007 Ville Skyttä, <scop at xemacs.org>
5
;; Author: Ville Skyttä, <scop at xemacs.org>
6
;; Keywords: unix, desktop entry
8
;; This file is part of XEmacs.
10
;; XEmacs is free software; you can redistribute it and/or modify it
11
;; under the terms of the GNU General Public License as published by
12
;; the Free Software Foundation; either version 2, or (at your option)
15
;; XEmacs is distributed in the hope that it will be useful, but
16
;; WITHOUT ANY WARRANTY; without even the implied warranty of
17
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
;; General Public License for more details.
20
;; You should have received a copy of the GNU General Public License
21
;; along with XEmacs; see the file COPYING. If not, write to the Free
22
;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27
;; This mode provides basic functionality, eg. syntax highlighting and
28
;; validation for freedesktop.org desktop entry files.
33
;; Just install the XEmacs `text-modes' package, this mode is included.
34
;; See <http://www.xemacs.org/Documentation/packageGuide.html>.
37
;; Place this file in your load path somewhere (eg. site-lisp), and add
38
;; the following to your .emacs:
40
;; (autoload 'desktop-entry-mode "desktop-entry-mode" "Desktop Entry mode" t)
41
;; (add-to-list 'auto-mode-alist
42
;; '("\\.desktop\\(\\.in\\)?$" . desktop-entry-mode))
43
;; (add-hook 'desktop-entry-mode-hook 'turn-on-font-lock)
45
;; For more information about desktop entry files, see
46
;; <http://www.freedesktop.org/Standards/desktop-entry-spec>
48
;; This version is up to date with version 1.0 of the specification.
53
(require 'regexp-opt))
55
(defconst desktop-entry-mode-version "1.0 (spec 1.0)"
56
"Version of `desktop-entry-mode'.")
58
(defgroup desktop-entry nil
59
"Support for editing freedesktop.org desktop entry files."
62
(defcustom desktop-entry-validate-command "desktop-file-validate"
63
"*Command for validating desktop entry files."
65
:group 'desktop-entry)
67
(defgroup desktop-entry-faces nil
68
"Font lock faces for `desktop-entry-mode'."
69
:prefix "desktop-entry-"
73
(defface desktop-entry-group-header-face
74
'((((class color) (background light)) (:foreground "mediumblue" :bold t))
75
(((class color) (background dark)) (:foreground "lightblue" :bold t))
77
"*Face for highlighting desktop entry group headers."
78
:group 'desktop-entry-faces)
80
(defface desktop-entry-deprecated-keyword-face
81
'((((class color)) (:background "yellow" :foreground "black" :strikethru t))
83
"*Face for highlighting deprecated desktop entry keys."
84
:group 'desktop-entry-faces)
86
(defface desktop-entry-unknown-keyword-face
87
'((((class color)) (:foreground "red3" :underline t))
90
"*Face for highlighting unknown desktop entry keys."
91
:group 'desktop-entry-faces)
93
(defface desktop-entry-value-face
94
'((((class color) (background light)) (:foreground "darkgreen"))
95
(((class color) (background dark)) (:foreground "lightgreen"))
97
"*Face for highlighting desktop entry values."
98
:group 'desktop-entry-faces)
100
(defface desktop-entry-locale-face
101
'((((class color) (background light)) (:foreground "dimgray"))
102
(((class color) (background dark)) (:foreground "lightgray"))
104
"*Face for highlighting desktop entry locales."
105
:group 'desktop-entry-faces)
107
(defconst desktop-entry-keywords
132
;; Reserved for use with KDE
137
;; Used by KDE for entries of the FSDevice type
144
"\\|X-[A-Za-z0-9-]+\\)"))
145
"Expression for matching desktop entry keys.")
147
(defconst desktop-entry-deprecated-keywords
150
"\\(\\<Type\\s-*=\\s-*MimeType\\>\\|"
168
"Expression for matching deprecated desktop entry keys.")
170
(defconst desktop-entry-group-header-re
171
"^\\[\\(X-[^\][]+\\|\\(?:Desktop \\(?:Entry\\|Action [a-zA-Z]+\\)\\)\\)\\]"
172
"Regular expression for matching desktop entry group headers.")
174
(defconst desktop-entry-font-lock-keywords
176
(cons "^\\s-*#.*$" '(0 'font-lock-comment-face))
177
(cons (concat "^" desktop-entry-deprecated-keywords)
178
'(0 'desktop-entry-deprecated-keyword-face))
179
(cons (concat "^" desktop-entry-keywords) '(0 'font-lock-keyword-face))
180
(cons "^[A-Za-z0-9-]+" '(0 'desktop-entry-unknown-keyword-face))
181
(cons desktop-entry-group-header-re '(1 'desktop-entry-group-header-face))
182
(cons "^[A-Za-z0-9-]+?\\s-*=\\s-*\\(.*\\)"
183
'(1 'desktop-entry-value-face))
184
(cons "^[A-Za-z0-9-]+?\\[\\([^\]]+\\)\\]\\s-*=\\s-*\\(.*\\)"
185
'((1 'desktop-entry-locale-face)
186
(2 'desktop-entry-value-face)))
188
"Highlighting rules for `desktop-entry-mode' buffers.")
190
(defvar desktop-entry-imenu-generic-expression
191
`((nil ,desktop-entry-group-header-re 1))
192
"Imenu generic expression for `desktop-entry-mode'.
193
See `imenu-generic-expression'.")
196
(defun desktop-entry-mode ()
197
"Major mode for editing freedesktop.org desktop entry files.
198
See <http://www.freedesktop.org/Standards/desktop-entry-spec> for more
199
information. See `desktop-entry-mode-version' for information about which
200
version of the specification this mode is up to date with.
202
Turning on desktop entry mode calls the value of the variable
203
`desktop-entry-mode-hook' with no args, if that value is non-nil."
205
(set (make-local-variable 'imenu-generic-expression)
206
'((nil "^\\s-*\\(.*\\)\\s-*=" 1)))
207
(set (make-local-variable 'compile-command)
208
(concat desktop-entry-validate-command " " buffer-file-name))
209
(set (make-local-variable 'compilation-buffer-name-function)
210
(lambda (x) (concat "*desktop-file-validate "
211
(file-name-nondirectory buffer-file-name) "*")))
212
(set (make-local-variable 'comment-start) "# ")
213
(set (make-local-variable 'comment-end) "")
214
(set (make-local-variable 'comment-start-skip) "#+ *")
215
(setq major-mode 'desktop-entry-mode mode-name "Desktop Entry")
216
(set (make-local-variable 'imenu-generic-expression)
217
desktop-entry-imenu-generic-expression)
218
(unless (featurep 'xemacs) ;; font-lock support for GNU Emacs
219
(set (make-local-variable 'font-lock-defaults)
220
'(desktop-entry-font-lock-keywords)))
221
(run-hooks 'desktop-entry-mode-hook))
223
(defun desktop-entry-validate ()
224
"Validate desktop entry in the current buffer."
227
(compile compile-command))
229
;;;###autoload(add-to-list 'auto-mode-alist '("\\.desktop\\(\\.in\\)?$" . desktop-entry-mode))
231
(provide 'desktop-entry-mode)
233
;;; desktop-entry-mode.el ends here