1 ;;; desktop-entry-mode.el --- freedesktop.org desktop entry editing
3 ;; Copyright (C) 2003-2004, 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., 59 Temple Place - Suite 330, Boston, MA
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 0.9.4 of the specification.
52 (defconst desktop-entry-mode-version
"0.94 (spec 0.9.4)"
53 "Version of `desktop-entry-mode'.")
55 (defgroup desktop-entry nil
56 "Support for editing freedesktop.org desktop entry files."
59 (defcustom desktop-entry-validate-command
"desktop-file-validate"
60 "*Command for validating desktop entry files."
62 :group
'desktop-entry
)
64 (defgroup desktop-entry-faces nil
65 "Font lock faces for `desktop-entry-mode'."
66 :prefix
"desktop-entry-"
70 (defface desktop-entry-group-header-face
71 '((((class color
) (background light
)) (:foreground
"mediumblue" :bold t
))
72 (((class color
) (background dark
)) (:foreground
"lightblue" :bold t
))
74 "*Face for highlighting desktop entry group headers."
75 :group
'desktop-entry-faces
)
77 (defface desktop-entry-value-face
78 '((((class color
) (background light
)) (:foreground
"darkgreen"))
79 (((class color
) (background dark
)) (:foreground
"lightgreen"))
81 "*Face for highlighting desktop entry values."
82 :group
'desktop-entry-faces
)
84 (defface desktop-entry-locale-face
85 '((((class color
) (background light
)) (:foreground
"dimgray"))
86 (((class color
) (background dark
)) (:foreground
"lightgray"))
88 "*Face for highlighting desktop entry locales."
89 :group
'desktop-entry-faces
)
91 (defconst desktop-entry-keywords
128 ;; Reserved for use with KDE as of spec 0.9.4.
134 "\\|X-[A-Za-z0-9-]+\\)"))
135 "Expression for matching desktop entry keys.")
137 (defconst desktop-entry-group-header-re
138 "^\\[\\(X-[^\][]+\\|\\(?:Desktop \\(?:Entry\\|Action [a-zA-Z]+\\)\\)\\)\\]"
139 "Regular expression for matching desktop entry group headers.")
141 (defconst desktop-entry-font-lock-keywords
143 (cons "^\\s-*#.*$" '(0 'font-lock-comment-face
))
144 (cons (concat "^" desktop-entry-keywords
) '(0 'font-lock-keyword-face
))
145 (cons desktop-entry-group-header-re
'(1 'desktop-entry-group-header-face
))
146 (cons "^[A-Za-z0-9-]+?\\s-*=\\s-*\\(.*\\)"
147 '(1 'desktop-entry-value-face
))
148 (cons "^[A-Za-z0-9-]+?\\[\\([^\]]+\\)\\]\\s-*=\\s-*\\(.*\\)"
149 '((1 'desktop-entry-locale-face
)
150 (2 'desktop-entry-value-face
)))
152 "Highlighting rules for `desktop-entry-mode' buffers.")
154 (defvar desktop-entry-imenu-generic-expression
155 `((nil ,desktop-entry-group-header-re
1))
156 "Imenu generic expression for `desktop-entry-mode'.
157 See `imenu-generic-expression'.")
160 (defun desktop-entry-mode ()
161 "Major mode for editing freedesktop.org desktop entry files.
162 See <http://www.freedesktop.org/Standards/desktop-entry-spec> for more
163 information. See `desktop-entry-mode-version' for information about which
164 version of the specification this mode is up to date with.
166 Turning on desktop entry mode calls the value of the variable
167 `desktop-entry-mode-hook' with no args, if that value is non-nil."
169 (set (make-local-variable 'imenu-generic-expression
)
170 '((nil "^\\s-*\\(.*\\)\\s-*=" 1)))
171 (set (make-local-variable 'compile-command
)
172 (concat desktop-entry-validate-command
" " buffer-file-name
))
173 (set (make-local-variable 'compilation-buffer-name-function
)
174 (lambda (x) (concat "*desktop-file-validate "
175 (file-name-nondirectory buffer-file-name
) "*")))
176 (set (make-local-variable 'comment-start
) "# ")
177 (set (make-local-variable 'comment-end
) "")
178 (set (make-local-variable 'comment-start-skip
) "#+ *")
179 (setq major-mode
'desktop-entry-mode mode-name
"Desktop Entry")
180 (set (make-local-variable 'imenu-generic-expression
)
181 desktop-entry-imenu-generic-expression
)
182 (unless (featurep 'xemacs
) ;; font-lock support for GNU Emacs
183 (set (make-local-variable 'font-lock-defaults
)
184 '(desktop-entry-font-lock-keywords)))
185 (run-hooks 'desktop-entry-mode-hook
))
187 (defun desktop-entry-validate ()
188 "Validate desktop entry in the current buffer."
191 (compile compile-command
))
193 ;;;###autoload(add-to-list 'auto-mode-alist '("\\.desktop\\(\\.in\\)?$" . desktop-entry-mode))
195 (provide 'desktop-entry-mode
)
197 ;;; desktop-entry-mode.el ends here