• R/O
  • SSH
  • HTTPS

macemacsjp: 提交


Commit MetaInfo

修订版580 (tree)
时间2012-02-05 20:07:07
作者sakito

Log Message

add # comment, and others

更改概述

差异

--- applescript-mode/trunk/applescript-mode.el (revision 579)
+++ applescript-mode/trunk/applescript-mode.el (revision 580)
@@ -1,6 +1,6 @@
1-;;; applescript-mode.el --- major mode for editing AppleScript source
1+;;; applescript-mode.el --- Major mode for editing AppleScript source
22
3-;; Copyright (C) 2004 MacEmacs JP Project
3+;; Copyright (C) 2004-2012 MacEmacs JP Project
44
55 ;;; Credits:
66 ;; Copyright (C) 2003,2004 FUJIMOTO Hisakuni
@@ -9,9 +9,12 @@
99 ;; http://pc.2ch.net/test/read.cgi/mac/1034581863/
1010 ;; Copyright (C) 2004 Harley Gorrell <harley@mahalito.net>
1111 ;; http://www.mahalito.net/~harley/elisp/osx-osascript.el
12+;; Copyright (C) 2009 Ian Eure
13+;; https://github.com/ieure/applescript-mode
1214
1315 ;; Author: sakito <sakito@users.sourceforge.jp>
14-;; Keywords: languages, tools
16+;; Version: $Revision$
17+;; Keywords: AppleScript languages
1518
1619 (defconst applescript-mode-version "$Revision$"
1720 "The current version of the AppleScript mode.")
@@ -19,20 +22,24 @@
1922 (defconst applescript-mode-help-address "sakito@users.sourceforge.jp"
2023 "Address accepting submission of bug reports.")
2124
22-;; This file is free software; you can redistribute it and/or modify
25+;;; This file is NOT part of GNU Emacs
26+
27+;;; License
28+;;
29+;; This program is free software; you can redistribute it and/or modify
2330 ;; it under the terms of the GNU General Public License as published by
24-;; the Free Software Foundation; either version 2, or (at your option)
31+;; the Free Software Foundation; either version 3, or (at your option)
2532 ;; any later version.
2633
27-;; This file is distributed in the hope that it will be useful,
34+;; This program is distributed in the hope that it will be useful,
2835 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2936 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3037 ;; GNU General Public License for more details.
3138
3239 ;; You should have received a copy of the GNU General Public License
33-;; along with GNU Emacs; see the file COPYING. If not, write to
34-;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
35-;; Boston, MA 02111-1307, USA.
40+;; along with this program; see the file COPYING. If not, write to
41+;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
42+;; Floor, Boston, MA 02110-1301, USA.
3643
3744 ;;; Commentary:
3845
@@ -40,10 +47,9 @@
4047
4148 ;;; Usage:
4249 ;; To use applescript-mode.el put the following line in your .emacs:
43-;; (autoload 'applescript-mode "applescript-mode" "major mode for editing AppleScript source." t)
44-;; (setq auto-mode-alist
45-;; (cons '("\\.applescript$" . applescript-mode) auto-mode-alist)
46-;; )
50+;; (autoload 'applescript-mode "applescript-mode"
51+;; "Major mode for editing AppleScript source." t)
52+;; (add-to-list 'auto-mode-alist '("\\.applescript$" . applescript-mode))
4753
4854 ;; Please use the SourceForge MacEmacs JP Project to submit bugs or
4955 ;; patches:
@@ -59,11 +65,9 @@
5965
6066 ;;; Code:
6167
62-
63-
6468 ;; user customize variables
6569 (defgroup applescript nil
66- "Support for the AppleScript, <http://www.apple.com/applescript/>"
70+ "Support for AppleScript, <http://www.apple.com/applescript/>"
6771 :group 'languages
6872 :prefix "as-")
6973
@@ -113,46 +117,39 @@
113117 (or (face-differs-from-default-p 'as-pseudo-keyword-face)
114118 (copy-face 'font-lock-keyword-face 'as-pseudo-keyword-face))
115119 (or (face-differs-from-default-p 'as-command-face)
116- (copy-face 'font-lock-keyword-face 'as-command-face))
117- )
120+ (copy-face 'font-lock-keyword-face 'as-command-face)))
118121 (add-hook 'font-lock-mode-hook 'as-font-lock-mode-hook)
119122
120-(defvar applescript-font-lock-keywords
123+(defconst applescript-font-lock-keywords
121124 (let (
122125 ;; expressions and control Statements
123- (kw1 (mapconcat 'identity
124- '("and" "app" "application" "considering" "div"
125- "else" "end" "exit" "is" "mod" "not" "on" "or"
126- "if" "ignoring" "reopen" "repeat"
127- "tell" "then" "to"
128- "using[ \t]terms[ \t]from"
129- "with[ \t]timeout" "with[ \t]transaction"
130- )
131- "\\|"))
126+ (kw1 (regexp-opt
127+ '("and" "app" "application" "considering" "div"
128+ "else" "end" "exit" "is" "mod" "not" "on" "or"
129+ "if" "ignoring" "reopen" "repeat" "return"
130+ "tell" "then" "to" "try"
131+ "using[ \t]terms[ \t]from"
132+ "with[ \t]timeout" "with[ \t]transaction")))
132133 ;; commands
133- (kw2 (mapconcat 'identity
134- '("ASCII[ \t]character" "ASCII[ \t]number" "activate" "AGStart"
135- "beep" "copy" "count" "choose[ \t]application"
136- "choose[ \t]file" "choose[ \t]folder" "close[ \t]access"
137- "current[ \t]date" "display[ \t]dialog" "get" "get[ \t]EOF"
138- "info[ \t]for" "launch" "list[ \t]disks" "list[ \t]folder"
139- "load[ \t]script" "log" "monitor[ \t]depth" "max[ \t]monitor[ \t]depth"
140- "min[ \t]monitor[ \t]depth" "new[ \t]file" "offset"
141- "open[ \t]for[ \t]access" "path[ \t]to" "random[ \t]number"
142- "read" "round" "run" "run[ \t]script" "scripting[ \t]component"
143- "set" "set[ \t]EOF" "set[ \t]monitor[ \t]depth" "set[ \t]volume"
144- "start[ \t]log" "stop[ \t]log" "store[ \t]script"
145- "time[ \t]to[ \t]GMT" "write"
146- )
147- "\\|"))
134+ (kw2 (regexp-opt
135+ '("ASCII[ \t]character" "ASCII[ \t]number" "activate" "AGStart"
136+ "beep" "copy" "count" "choose[ \t]application"
137+ "choose[ \t]file" "choose[ \t]folder" "close[ \t]access"
138+ "current[ \t]date" "display[ \t]dialog" "get" "get[ \t]EOF"
139+ "info[ \t]for" "launch" "list[ \t]disks" "list[ \t]folder"
140+ "load[ \t]script" "log" "monitor[ \t]depth" "max[ \t]monitor[ \t]depth"
141+ "min[ \t]monitor[ \t]depth" "new[ \t]file" "offset"
142+ "open[ \t]for[ \t]access" "path[ \t]to" "random[ \t]number"
143+ "read" "round" "run" "run[ \t]script" "scripting[ \t]component"
144+ "set" "set[ \t]EOF" "set[ \t]monitor[ \t]depth" "set[ \t]volume"
145+ "start[ \t]log" "stop[ \t]log" "store[ \t]script"
146+ "time[ \t]to[ \t]GMT" "write"
147+ )))
148148 ;; misc
149- (kw3 (mapconcat 'identity
150- '("buttons" "default[ \t]answer" "default[ \t]button"
151- "to[ \t]begining[ \t]of" "to[ \t]word" "starting[ \t]at"
152- "with[ \t]icon" "write[ \t]permission"
153- )
154- "\\|"))
155- )
149+ (kw3 (regexp-opt
150+ '("buttons" "default[ \t]answer" "default[ \t]button"
151+ "to[ \t]begining[ \t]of" "to[ \t]word" "starting[ \t]at"
152+ "with[ \t]icon" "write[ \t]permission"))))
156153 (list
157154 ;; keywords
158155 (cons (concat "\\b\\(" kw1 "\\)\\b[ \n\t(]") 1)
@@ -166,9 +163,7 @@
166163 1 font-lock-function-name-face)
167164 ;; pseudo-keywords
168165 '("\\b\\(it\\|me\\|my\\|true\\|false\\)\\b"
169- 1 as-pseudo-keyword-face)
170- )
171- ))
166+ 1 as-pseudo-keyword-face))))
172167 (put 'applescript-mode 'font-lock-defaults '(applescript-font-lock-keywords))
173168
174169 ;; Major mode boilerplate
@@ -181,26 +176,6 @@
181176 (defvar applescript-mode-hook nil
182177 "*Hook called by `applescript-mode'.")
183178
184-(defvar as-mode-map ()
185- "Keymap used in `applescript-mode' buffers.")
186-(if as-mode-map
187- nil
188- (setq as-mode-map (make-sparse-keymap))
189- ;; Key bindings
190-
191- ;; subprocess commands
192- (define-key as-mode-map "\C-c\C-c" 'as-execute-buffer)
193- (define-key as-mode-map "\C-c\C-s" 'as-execute-string)
194- (define-key as-mode-map "\C-c|" 'as-execute-region)
195-
196- ;; Miscellaneous
197- (define-key as-mode-map "\C-c;" 'comment-region)
198- (define-key as-mode-map "\C-c:" 'uncomment-region)
199-
200- ;; information
201- ;(define-key as-mode-map "\C-c\C-v" 'as-mode-version)
202- )
203-
204179 (defvar as-mode-syntax-table nil
205180 "Syntax table used in `applescript-mode' buffers.")
206181 (when (not as-mode-syntax-table)
@@ -226,6 +201,8 @@
226201 (modify-syntax-entry ?\\ "." as-mode-syntax-table)
227202 (modify-syntax-entry ?\' "." as-mode-syntax-table)
228203
204+ ;; a single hash starts a comment
205+ (modify-syntax-entry ?\# "<" as-mode-syntax-table)
229206 ;; a double hyphen starts a comment
230207 (modify-syntax-entry ?- ". 12" as-mode-syntax-table)
231208
@@ -236,15 +213,51 @@
236213 ;; define parentheses to match
237214 (modify-syntax-entry ?\( "()1" as-mode-syntax-table)
238215 (modify-syntax-entry ?\) ")(4" as-mode-syntax-table)
239- (modify-syntax-entry ?* ". 23b" as-mode-syntax-table)
240- )
216+ (modify-syntax-entry ?* ". 23b" as-mode-syntax-table))
241217
218+(defvar as-mode-map ()
219+ "Keymap used in `applescript-mode' buffers.")
220+;; Menu definitions, only relevent if you have the easymenu.el package
221+;; (standard in the latest Emacs 19 and XEmacs 19 distributions).
222+(defvar as-menu nil
223+ "Menu for AppleScript Mode.
224+This menu will get created automatically if you have the
225+`easymenu' package. Note that the latest X/Emacs releases
226+contain this package.")
227+(if as-mode-map
228+ nil
229+ (setq as-mode-map
230+ (let ((map (make-sparse-keymap)))
231+ ;; Key bindings
232+
233+ ;; subprocess commands
234+ (define-key map "\C-c\C-c" 'as-execute-buffer)
235+ (define-key map "\C-c\C-s" 'as-execute-string)
236+ (define-key map "\C-c|" 'as-execute-region)
237+
238+ ;; Miscellaneous
239+ (define-key map "\C-c;" 'comment-region)
240+ (define-key map "\C-c:" 'uncomment-region)
241+
242+ (easy-menu-define as-menu map "AppleScript Mode menu"
243+ '("AppleScript"
244+ ["Comment Out Region" comment-region (mark)]
245+ ["Uncomment Region" uncomment-region (mark)]
246+ "-"
247+ ["Execute buffer" as-execute-buffer t]
248+ ["Execute region" as-execute-region (mark)]
249+ ["Execute string" as-execute-string t]
250+ "-"
251+ ["Mode Version" as-mode-version t]
252+ ["AppleScript Version" as-language-version t]))
253+ map)))
254+
242255 ;; Utilities
243256 (defmacro as-safe (&rest body)
244257 "Safely execute BODY, return nil if an error occurred."
245- (` (condition-case nil
246- (progn (,@ body))
247- (error nil))))
258+ `(condition-case nil
259+ (progn (,@ body))
260+ (error nil)))
248261
249262 (defsubst as-keep-region-active ()
250263 "Keep the region active in XEmacs."
@@ -276,39 +289,13 @@
276289 ((eq position 'bod) (as-beginning-of-handler 'either))
277290 ((eq position 'eod) (as-end-of-handler 'either))
278291 ;; Kind of funny, I know, but useful for as-up-exception.
279- ((eq position 'bob) (beginning-of-buffer))
280- ((eq position 'eob) (end-of-buffer))
292+ ((eq position 'bob) (goto-char (point-min)))
293+ ((eq position 'eob) (goto-char (point-max)))
281294 ((eq position 'boi) (back-to-indentation))
282295 ((eq position 'bos) (as-goto-initial-line))
283- (t (error "Unknown buffer position requested: %s" position))
284- )
285- (prog1
286- (point)
287- (goto-char here))))
296+ (t (error "Unknown buffer position requested: %s" position)))
297+ (prog1 (point) (goto-char here))))
288298
289-;; Menu definitions, only relevent if you have the easymenu.el package
290-;; (standard in the latest Emacs 19 and XEmacs 19 distributions).
291-(defvar as-menu nil
292- "Menu for AppleScript Mode.
293-This menu will get created automatically if you have the
294-`easymenu' package. Note that the latest X/Emacs releases
295-contain this package.")
296-
297-(and (as-safe (require 'easymenu) t)
298- (easy-menu-define
299- as-menu as-mode-map "AppleScript Mode menu"
300- '("AppleScript"
301- ["Comment Out Region" comment-region (mark)]
302- ["Uncomment Region" uncomment-region (mark)]
303- "-"
304- ["Execute buffer" as-execute-buffer t]
305- ["Execute region" as-execute-region (mark)]
306- ["Execute string" as-execute-string t]
307- "-"
308- ["Mode Version" as-mode-version t]
309- ["AppleScript Version" as-language-version t]
310- )))
311-
312299 ;;;###autoload
313300 (defun applescript-mode ()
314301 "Major mode for editing AppleScript files."
@@ -346,8 +333,7 @@
346333 comment-start "-- "
347334 comment-end ""
348335 comment-start-skip "---*[ \t]*"
349- comment-column 40
350- )
336+ comment-column 40)
351337
352338 ;; Support for outline-minor-mode
353339 (set (make-local-variable 'outline-regexp)
@@ -361,10 +347,8 @@
361347 ;; Run the mode hook. Note that applescript-mode-hook is deprecated.
362348 (if applescript-mode-hook
363349 (run-hooks 'applescript-mode-hook)
364- (run-hooks 'applescript-mode-hook))
350+ (run-hooks 'applescript-mode-hook)))
365351
366- )
367-
368352 (when (not (or (rassq 'applescript-mode auto-mode-alist)
369353 (push '("\\.applescript$" . applescript-mode) auto-mode-alist))))
370354
@@ -384,9 +368,7 @@
384368 (defun as-execute-string (string &optional async)
385369 "Send the argument STRING to an AppleScript."
386370 (interactive "sExecute AppleScript: ")
387- (save-excursion
388- (set-buffer (get-buffer-create
389- (generate-new-buffer-name as-output-buffer)))
371+ (with-temp-buffer
390372 (insert string)
391373 (as-execute-region (point-min) (point-max) async)))
392374
@@ -397,12 +379,12 @@
397379 (as-current-win (selected-window)))
398380 (pop-to-buffer as-output-buffer)
399381 (insert (as-execute-code region))
400- (select-window as-current-win)
401- ))
382+ (select-window as-current-win)))
402383
403384 (defun as-execute-code (code)
404385 "pop to the AppleScript buffer, run the code and display the results."
405- (as-decode-string (do-applescript (as-string-to-sjis-string-with-escape code))))
386+ (as-decode-string
387+ (do-applescript (as-string-to-sjis-string-with-escape code))))
406388
407389 (defun as-mode-version ()
408390 "Echo the current version of `applescript-mode' in the minibuffer."
@@ -413,7 +395,8 @@
413395 (defun as-language-version()
414396 "Echo the current version of AppleScript Version in the minibuffer."
415397 (interactive)
416- (message "Using AppleScript version %s" (as-execute-code "AppleScript's version"))
398+ (message "Using AppleScript version %s"
399+ (as-execute-code "AppleScript's version"))
417400 (as-keep-region-active))
418401
419402 ;; as-beginning-of-handler, as-end-of-handler,as-goto-initial-line not yet
@@ -478,7 +461,7 @@
478461
479462 ;; as integer
480463 ((string-match "\\`\\s-*\\([0-9]+\\)\\s-*\\'" retstr)
481- (string-to-int (match-string 1 retstr)))
464+ (string-to-number (match-string 1 retstr)))
482465
483466 ;; else
484467 (t (intern retstr))))
Show on old repository browser