svnno****@sourc*****
svnno****@sourc*****
2012年 2月 5日 (日) 20:07:07 JST
Revision: 580 http://sourceforge.jp/projects/macemacsjp/svn/view?view=rev&revision=580 Author: sakito Date: 2012-02-05 20:07:07 +0900 (Sun, 05 Feb 2012) Log Message: ----------- add # comment, and others Modified Paths: -------------- applescript-mode/trunk/applescript-mode.el -------------- next part -------------- Modified: applescript-mode/trunk/applescript-mode.el =================================================================== --- applescript-mode/trunk/applescript-mode.el 2012-01-12 23:57:36 UTC (rev 579) +++ applescript-mode/trunk/applescript-mode.el 2012-02-05 11:07:07 UTC (rev 580) @@ -1,6 +1,6 @@ -;;; applescript-mode.el --- major mode for editing AppleScript source +;;; applescript-mode.el --- Major mode for editing AppleScript source -;; Copyright (C) 2004 MacEmacs JP Project +;; Copyright (C) 2004-2012 MacEmacs JP Project ;;; Credits: ;; Copyright (C) 2003,2004 FUJIMOTO Hisakuni @@ -9,9 +9,12 @@ ;; http://pc.2ch.net/test/read.cgi/mac/1034581863/ ;; Copyright (C) 2004 Harley Gorrell <harle****@mahal*****> ;; http://www.mahalito.net/~harley/elisp/osx-osascript.el +;; Copyright (C) 2009 Ian Eure +;; https://github.com/ieure/applescript-mode ;; Author: sakito <sakit****@users*****> -;; Keywords: languages, tools +;; Version: $Revision$ +;; Keywords: AppleScript languages (defconst applescript-mode-version "$Revision$" "The current version of the AppleScript mode.") @@ -19,20 +22,24 @@ (defconst applescript-mode-help-address "sakit****@users*****" "Address accepting submission of bug reports.") -;; This file is free software; you can redistribute it and/or modify +;;; This file is NOT part of GNU Emacs + +;;; License +;; +;; This program 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, or (at your option) +;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. -;; This file is distributed in the hope that it will be useful, +;; This program 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; see the file COPYING. If not, write to -;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. +;; along with this program; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth +;; Floor, Boston, MA 02110-1301, USA. ;;; Commentary: @@ -40,10 +47,9 @@ ;;; Usage: ;; To use applescript-mode.el put the following line in your .emacs: -;; (autoload 'applescript-mode "applescript-mode" "major mode for editing AppleScript source." t) -;; (setq auto-mode-alist -;; (cons '("\\.applescript$" . applescript-mode) auto-mode-alist) -;; ) +;; (autoload 'applescript-mode "applescript-mode" +;; "Major mode for editing AppleScript source." t) +;; (add-to-list 'auto-mode-alist '("\\.applescript$" . applescript-mode)) ;; Please use the SourceForge MacEmacs JP Project to submit bugs or ;; patches: @@ -59,11 +65,9 @@ ;;; Code: - - ;; user customize variables (defgroup applescript nil - "Support for the AppleScript, <http://www.apple.com/applescript/>" + "Support for AppleScript, <http://www.apple.com/applescript/>" :group 'languages :prefix "as-") @@ -113,46 +117,39 @@ (or (face-differs-from-default-p 'as-pseudo-keyword-face) (copy-face 'font-lock-keyword-face 'as-pseudo-keyword-face)) (or (face-differs-from-default-p 'as-command-face) - (copy-face 'font-lock-keyword-face 'as-command-face)) - ) + (copy-face 'font-lock-keyword-face 'as-command-face))) (add-hook 'font-lock-mode-hook 'as-font-lock-mode-hook) -(defvar applescript-font-lock-keywords +(defconst applescript-font-lock-keywords (let ( ;; expressions and control Statements - (kw1 (mapconcat 'identity - '("and" "app" "application" "considering" "div" - "else" "end" "exit" "is" "mod" "not" "on" "or" - "if" "ignoring" "reopen" "repeat" - "tell" "then" "to" - "using[ \t]terms[ \t]from" - "with[ \t]timeout" "with[ \t]transaction" - ) - "\\|")) + (kw1 (regexp-opt + '("and" "app" "application" "considering" "div" + "else" "end" "exit" "is" "mod" "not" "on" "or" + "if" "ignoring" "reopen" "repeat" "return" + "tell" "then" "to" "try" + "using[ \t]terms[ \t]from" + "with[ \t]timeout" "with[ \t]transaction"))) ;; commands - (kw2 (mapconcat 'identity - '("ASCII[ \t]character" "ASCII[ \t]number" "activate" "AGStart" - "beep" "copy" "count" "choose[ \t]application" - "choose[ \t]file" "choose[ \t]folder" "close[ \t]access" - "current[ \t]date" "display[ \t]dialog" "get" "get[ \t]EOF" - "info[ \t]for" "launch" "list[ \t]disks" "list[ \t]folder" - "load[ \t]script" "log" "monitor[ \t]depth" "max[ \t]monitor[ \t]depth" - "min[ \t]monitor[ \t]depth" "new[ \t]file" "offset" - "open[ \t]for[ \t]access" "path[ \t]to" "random[ \t]number" - "read" "round" "run" "run[ \t]script" "scripting[ \t]component" - "set" "set[ \t]EOF" "set[ \t]monitor[ \t]depth" "set[ \t]volume" - "start[ \t]log" "stop[ \t]log" "store[ \t]script" - "time[ \t]to[ \t]GMT" "write" - ) - "\\|")) + (kw2 (regexp-opt + '("ASCII[ \t]character" "ASCII[ \t]number" "activate" "AGStart" + "beep" "copy" "count" "choose[ \t]application" + "choose[ \t]file" "choose[ \t]folder" "close[ \t]access" + "current[ \t]date" "display[ \t]dialog" "get" "get[ \t]EOF" + "info[ \t]for" "launch" "list[ \t]disks" "list[ \t]folder" + "load[ \t]script" "log" "monitor[ \t]depth" "max[ \t]monitor[ \t]depth" + "min[ \t]monitor[ \t]depth" "new[ \t]file" "offset" + "open[ \t]for[ \t]access" "path[ \t]to" "random[ \t]number" + "read" "round" "run" "run[ \t]script" "scripting[ \t]component" + "set" "set[ \t]EOF" "set[ \t]monitor[ \t]depth" "set[ \t]volume" + "start[ \t]log" "stop[ \t]log" "store[ \t]script" + "time[ \t]to[ \t]GMT" "write" + ))) ;; misc - (kw3 (mapconcat 'identity - '("buttons" "default[ \t]answer" "default[ \t]button" - "to[ \t]begining[ \t]of" "to[ \t]word" "starting[ \t]at" - "with[ \t]icon" "write[ \t]permission" - ) - "\\|")) - ) + (kw3 (regexp-opt + '("buttons" "default[ \t]answer" "default[ \t]button" + "to[ \t]begining[ \t]of" "to[ \t]word" "starting[ \t]at" + "with[ \t]icon" "write[ \t]permission")))) (list ;; keywords (cons (concat "\\b\\(" kw1 "\\)\\b[ \n\t(]") 1) @@ -166,9 +163,7 @@ 1 font-lock-function-name-face) ;; pseudo-keywords '("\\b\\(it\\|me\\|my\\|true\\|false\\)\\b" - 1 as-pseudo-keyword-face) - ) - )) + 1 as-pseudo-keyword-face)))) (put 'applescript-mode 'font-lock-defaults '(applescript-font-lock-keywords)) ;; Major mode boilerplate @@ -181,26 +176,6 @@ (defvar applescript-mode-hook nil "*Hook called by `applescript-mode'.") -(defvar as-mode-map () - "Keymap used in `applescript-mode' buffers.") -(if as-mode-map - nil - (setq as-mode-map (make-sparse-keymap)) - ;; Key bindings - - ;; subprocess commands - (define-key as-mode-map "\C-c\C-c" 'as-execute-buffer) - (define-key as-mode-map "\C-c\C-s" 'as-execute-string) - (define-key as-mode-map "\C-c|" 'as-execute-region) - - ;; Miscellaneous - (define-key as-mode-map "\C-c;" 'comment-region) - (define-key as-mode-map "\C-c:" 'uncomment-region) - - ;; information - ;(define-key as-mode-map "\C-c\C-v" 'as-mode-version) - ) - (defvar as-mode-syntax-table nil "Syntax table used in `applescript-mode' buffers.") (when (not as-mode-syntax-table) @@ -226,6 +201,8 @@ (modify-syntax-entry ?\\ "." as-mode-syntax-table) (modify-syntax-entry ?\' "." as-mode-syntax-table) + ;; a single hash starts a comment + (modify-syntax-entry ?\# "<" as-mode-syntax-table) ;; a double hyphen starts a comment (modify-syntax-entry ?- ". 12" as-mode-syntax-table) @@ -236,15 +213,51 @@ ;; define parentheses to match (modify-syntax-entry ?\( "()1" as-mode-syntax-table) (modify-syntax-entry ?\) ")(4" as-mode-syntax-table) - (modify-syntax-entry ?* ". 23b" as-mode-syntax-table) - ) + (modify-syntax-entry ?* ". 23b" as-mode-syntax-table)) +(defvar as-mode-map () + "Keymap used in `applescript-mode' buffers.") +;; Menu definitions, only relevent if you have the easymenu.el package +;; (standard in the latest Emacs 19 and XEmacs 19 distributions). +(defvar as-menu nil + "Menu for AppleScript Mode. +This menu will get created automatically if you have the +`easymenu' package. Note that the latest X/Emacs releases +contain this package.") +(if as-mode-map + nil + (setq as-mode-map + (let ((map (make-sparse-keymap))) + ;; Key bindings + + ;; subprocess commands + (define-key map "\C-c\C-c" 'as-execute-buffer) + (define-key map "\C-c\C-s" 'as-execute-string) + (define-key map "\C-c|" 'as-execute-region) + + ;; Miscellaneous + (define-key map "\C-c;" 'comment-region) + (define-key map "\C-c:" 'uncomment-region) + + (easy-menu-define as-menu map "AppleScript Mode menu" + '("AppleScript" + ["Comment Out Region" comment-region (mark)] + ["Uncomment Region" uncomment-region (mark)] + "-" + ["Execute buffer" as-execute-buffer t] + ["Execute region" as-execute-region (mark)] + ["Execute string" as-execute-string t] + "-" + ["Mode Version" as-mode-version t] + ["AppleScript Version" as-language-version t])) + map))) + ;; Utilities (defmacro as-safe (&rest body) "Safely execute BODY, return nil if an error occurred." - (` (condition-case nil - (progn (,@ body)) - (error nil)))) + `(condition-case nil + (progn (,@ body)) + (error nil))) (defsubst as-keep-region-active () "Keep the region active in XEmacs." @@ -276,39 +289,13 @@ ((eq position 'bod) (as-beginning-of-handler 'either)) ((eq position 'eod) (as-end-of-handler 'either)) ;; Kind of funny, I know, but useful for as-up-exception. - ((eq position 'bob) (beginning-of-buffer)) - ((eq position 'eob) (end-of-buffer)) + ((eq position 'bob) (goto-char (point-min))) + ((eq position 'eob) (goto-char (point-max))) ((eq position 'boi) (back-to-indentation)) ((eq position 'bos) (as-goto-initial-line)) - (t (error "Unknown buffer position requested: %s" position)) - ) - (prog1 - (point) - (goto-char here)))) + (t (error "Unknown buffer position requested: %s" position))) + (prog1 (point) (goto-char here)))) -;; Menu definitions, only relevent if you have the easymenu.el package -;; (standard in the latest Emacs 19 and XEmacs 19 distributions). -(defvar as-menu nil - "Menu for AppleScript Mode. -This menu will get created automatically if you have the -`easymenu' package. Note that the latest X/Emacs releases -contain this package.") - -(and (as-safe (require 'easymenu) t) - (easy-menu-define - as-menu as-mode-map "AppleScript Mode menu" - '("AppleScript" - ["Comment Out Region" comment-region (mark)] - ["Uncomment Region" uncomment-region (mark)] - "-" - ["Execute buffer" as-execute-buffer t] - ["Execute region" as-execute-region (mark)] - ["Execute string" as-execute-string t] - "-" - ["Mode Version" as-mode-version t] - ["AppleScript Version" as-language-version t] - ))) - ;;;###autoload (defun applescript-mode () "Major mode for editing AppleScript files." @@ -346,8 +333,7 @@ comment-start "-- " comment-end "" comment-start-skip "---*[ \t]*" - comment-column 40 - ) + comment-column 40) ;; Support for outline-minor-mode (set (make-local-variable 'outline-regexp) @@ -361,10 +347,8 @@ ;; Run the mode hook. Note that applescript-mode-hook is deprecated. (if applescript-mode-hook (run-hooks 'applescript-mode-hook) - (run-hooks 'applescript-mode-hook)) + (run-hooks 'applescript-mode-hook))) - ) - (when (not (or (rassq 'applescript-mode auto-mode-alist) (push '("\\.applescript$" . applescript-mode) auto-mode-alist)))) @@ -384,9 +368,7 @@ (defun as-execute-string (string &optional async) "Send the argument STRING to an AppleScript." (interactive "sExecute AppleScript: ") - (save-excursion - (set-buffer (get-buffer-create - (generate-new-buffer-name as-output-buffer))) + (with-temp-buffer (insert string) (as-execute-region (point-min) (point-max) async))) @@ -397,12 +379,12 @@ (as-current-win (selected-window))) (pop-to-buffer as-output-buffer) (insert (as-execute-code region)) - (select-window as-current-win) - )) + (select-window as-current-win))) (defun as-execute-code (code) "pop to the AppleScript buffer, run the code and display the results." - (as-decode-string (do-applescript (as-string-to-sjis-string-with-escape code)))) + (as-decode-string + (do-applescript (as-string-to-sjis-string-with-escape code)))) (defun as-mode-version () "Echo the current version of `applescript-mode' in the minibuffer." @@ -413,7 +395,8 @@ (defun as-language-version() "Echo the current version of AppleScript Version in the minibuffer." (interactive) - (message "Using AppleScript version %s" (as-execute-code "AppleScript's version")) + (message "Using AppleScript version %s" + (as-execute-code "AppleScript's version")) (as-keep-region-active)) ;; as-beginning-of-handler, as-end-of-handler,as-goto-initial-line not yet @@ -478,7 +461,7 @@ ;; as integer ((string-match "\\`\\s-*\\([0-9]+\\)\\s-*\\'" retstr) - (string-to-int (match-string 1 retstr))) + (string-to-number (match-string 1 retstr))) ;; else (t (intern retstr))))