~elementary-os/ubuntu-package-imports/desktop-file-utils-xenial

« back to all changes in this revision

Viewing changes to misc/desktop-entry-mode.el

  • Committer: RabbitBot
  • Date: 2016-01-17 16:50:38 UTC
  • Revision ID: rabbitbot@elementary.io-20160117165038-3yu4qhcpf1rjfh01
Initial import, version 0.22-1ubuntu3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;;; desktop-entry-mode.el --- freedesktop.org desktop entry editing
 
2
 
 
3
;; Copyright (C) 2003-2004, 2006-2007 Ville Skyttä, <scop at xemacs.org>
 
4
 
 
5
;; Author:   Ville Skyttä, <scop at xemacs.org>
 
6
;; Keywords: unix, desktop entry
 
7
 
 
8
;; This file is part of XEmacs.
 
9
 
 
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)
 
13
;; any later version.
 
14
 
 
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.
 
19
 
 
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,
 
23
;; MA 02110-1301 USA.
 
24
 
 
25
;;; Commentary:
 
26
 
 
27
;; This mode provides basic functionality, eg. syntax highlighting and
 
28
;; validation for freedesktop.org desktop entry files.
 
29
;;
 
30
;; To install it:
 
31
;;
 
32
;;   In XEmacs:
 
33
;;   Just install the XEmacs `text-modes' package, this mode is included.
 
34
;;   See <http://www.xemacs.org/Documentation/packageGuide.html>.
 
35
;;
 
36
;;   In GNU Emacs:
 
37
;;   Place this file in your load path somewhere (eg. site-lisp), and add
 
38
;;   the following to your .emacs:
 
39
;;
 
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)
 
44
;;
 
45
;; For more information about desktop entry files, see
 
46
;;   <http://www.freedesktop.org/Standards/desktop-entry-spec>
 
47
;;
 
48
;; This version is up to date with version 1.0 of the specification.
 
49
 
 
50
;;; Code:
 
51
 
 
52
(eval-when-compile
 
53
  (require 'regexp-opt))
 
54
 
 
55
(defconst desktop-entry-mode-version "1.0 (spec 1.0)"
 
56
  "Version of `desktop-entry-mode'.")
 
57
 
 
58
(defgroup desktop-entry nil
 
59
  "Support for editing freedesktop.org desktop entry files."
 
60
  :group 'languages)
 
61
 
 
62
(defcustom desktop-entry-validate-command "desktop-file-validate"
 
63
  "*Command for validating desktop entry files."
 
64
  :type 'string
 
65
  :group 'desktop-entry)
 
66
 
 
67
(defgroup desktop-entry-faces nil
 
68
  "Font lock faces for `desktop-entry-mode'."
 
69
  :prefix "desktop-entry-"
 
70
  :group 'desktop-entry
 
71
  :group 'faces)
 
72
 
 
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))
 
76
    (t (:bold t)))
 
77
  "*Face for highlighting desktop entry group headers."
 
78
  :group 'desktop-entry-faces)
 
79
 
 
80
(defface desktop-entry-deprecated-keyword-face
 
81
  '((((class color)) (:background "yellow" :foreground "black" :strikethru t))
 
82
    )
 
83
  "*Face for highlighting deprecated desktop entry keys."
 
84
  :group 'desktop-entry-faces)
 
85
 
 
86
(defface desktop-entry-unknown-keyword-face
 
87
  '((((class color)) (:foreground "red3" :underline t))
 
88
    (t (:underline t))
 
89
    )
 
90
  "*Face for highlighting unknown desktop entry keys."
 
91
  :group 'desktop-entry-faces)
 
92
 
 
93
(defface desktop-entry-value-face
 
94
  '((((class color) (background light)) (:foreground "darkgreen"))
 
95
    (((class color) (background dark)) (:foreground "lightgreen"))
 
96
    )
 
97
  "*Face for highlighting desktop entry values."
 
98
  :group 'desktop-entry-faces)
 
99
 
 
100
(defface desktop-entry-locale-face
 
101
  '((((class color) (background light)) (:foreground "dimgray"))
 
102
    (((class color) (background dark)) (:foreground "lightgray"))
 
103
    )
 
104
  "*Face for highlighting desktop entry locales."
 
105
  :group 'desktop-entry-faces)
 
106
 
 
107
(defconst desktop-entry-keywords
 
108
  (eval-when-compile
 
109
    (concat
 
110
     "\\(?:"
 
111
     (regexp-opt
 
112
      '(
 
113
        "Type"
 
114
        "Version"
 
115
        "Name"
 
116
        "GenericName"
 
117
        "NoDisplay"
 
118
        "Comment"
 
119
        "Icon"
 
120
        "Hidden"
 
121
        "OnlyShowIn"
 
122
        "NotShowIn"
 
123
        "TryExec"
 
124
        "Exec"
 
125
        "Path"
 
126
        "Terminal"
 
127
        "MimeType"
 
128
        "Categories"
 
129
        "StartupNotify"
 
130
        "StartupWMClass"
 
131
        "URL"
 
132
        ;; Reserved for use with KDE
 
133
        "ServiceTypes"
 
134
        "DocPath"
 
135
        "KeyWords"
 
136
        "InitialPreference"
 
137
        ;; Used by KDE for entries of the FSDevice type
 
138
        "Dev"
 
139
        "FSType"
 
140
        "MountPoint"
 
141
        "ReadOnly"
 
142
        "UnmountIcon"
 
143
        ) 'words)
 
144
     "\\|X-[A-Za-z0-9-]+\\)"))
 
145
  "Expression for matching desktop entry keys.")
 
146
 
 
147
(defconst desktop-entry-deprecated-keywords
 
148
  (eval-when-compile
 
149
    (concat
 
150
     "\\(\\<Type\\s-*=\\s-*MimeType\\>\\|"
 
151
     (regexp-opt
 
152
      '(
 
153
        "Patterns"
 
154
        "DefaultApp"
 
155
        "Encoding"
 
156
        "MiniIcon"
 
157
        "TerminalOptions"
 
158
        "Protocols"
 
159
        "Extensions"
 
160
        "BinaryPattern"
 
161
        "MapNotify"
 
162
        "SwallowTitle"
 
163
        "SwallowExec"
 
164
        "SortOrder"
 
165
        "FilePattern"
 
166
        ) 'words)
 
167
     "\\)"))
 
168
  "Expression for matching deprecated desktop entry keys.")
 
169
 
 
170
(defconst desktop-entry-group-header-re
 
171
  "^\\[\\(X-[^\][]+\\|\\(?:Desktop \\(?:Entry\\|Action [a-zA-Z]+\\)\\)\\)\\]"
 
172
  "Regular expression for matching desktop entry group headers.")
 
173
 
 
174
(defconst desktop-entry-font-lock-keywords
 
175
  (list
 
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)))
 
187
   )
 
188
  "Highlighting rules for `desktop-entry-mode' buffers.")
 
189
 
 
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'.")
 
194
 
 
195
;;;###autoload
 
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.
 
201
 
 
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."
 
204
  (interactive)
 
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))
 
222
 
 
223
(defun desktop-entry-validate ()
 
224
  "Validate desktop entry in the current buffer."
 
225
  (interactive)
 
226
  (require 'compile)
 
227
  (compile compile-command))
 
228
 
 
229
;;;###autoload(add-to-list 'auto-mode-alist '("\\.desktop\\(\\.in\\)?$" . desktop-entry-mode))
 
230
 
 
231
(provide 'desktop-entry-mode)
 
232
 
 
233
;;; desktop-entry-mode.el ends here