⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generic-x.el

📁 windows版本的emacs
💻 EL
📖 第 1 页 / 共 3 页
字号:
;;; generic-x.el --- Extra Modes for generic-mode;; Copyright (C) 1997, 1998 Free Software Foundation, Inc.;; Author:  Peter Breton <pbreton@cs.umb.edu>;; Created: Tue Oct 08 1996;; Keywords: generic, comment, font-lock;; This file is part of GNU Emacs.;; GNU Emacs 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);; any later version.;; GNU Emacs 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.;;; Commentary:;;;; This file contains some pre-defined generic-modes.;;;; INSTALLATION:;;;; Add this line to your .emacs file:;;;;   (require 'generic-x);;;; You can decide which modes to load by setting the variable;; `generic-extras-enable-list'. Some platform-specific modes are;; affected by the variables `generic-define-mswindows-modes' and;; `generic-define-unix-modes' (which see).;;;; You can also send in new modes; if the file types a reasonably common,;; we would like to install them.;;;; PROBLEMS WHEN USED WITH FOLDING MODE:;;;; [The following relates to the obsolete selective-display technique.;; Folding mode should use invisible text properties instead. -- Dave;; Love];;;; From Anders Lindgren <andersl@csd.uu.se>;;;; Problem summary: Wayne Adams has found a problem when using folding;; mode in conjuction with font-lock for a mode defined in;; `generic-x.el'.;;;; The problem, as Wayne described it, was that error messages of the;; following form appeared when both font-lock and folding are used:;;;; >      - various msgs including "Fontifying region...(error Stack;; > overflow in regexp matcher)" appear;;;; I have just tracked down the cause of the problem.  The regexp:s in;; `generic-x.el' does not take into account the way that folding;; hides sections of the buffer.  The technique is known as;; `selective-display' and has been available for a very long time (I;; started using it back in the good old' Emacs 18 days).  Basically, a;; section is hidden by creating one very long line were the newline;; character (C-j) is replaced by a linefeed (C-m) character.;;;; Many other hiding packages, besides folding, use the same technique,;; the problem should occur when using them as well.;;;; The erroronous lines in `generic-extras' look like the following (this;; example is from the `ini' section):;;;;     '(("^\\(\\[.*\\]\\)"   1 'font-lock-constant-face);;       ("^\\(.*\\)="        1 'font-lock-variable-name-face);;;; The intention of these lines is to highlight lines of the following;; form:;;;; [foo];; bar = xxx;;;; However, since the `.' regexp symbol match the linefeed character the;; entire folded section is searched, resulting in a regexp stack;; overflow.;;;; Solution suggestion 2: Instead of using ".", use the sequence;; "[^\n\r]".  This will make the rules behave just as before, but they;; will work together with selective-display.;;; Code:(require 'generic)(require 'font-lock)(defgroup generic-x nil  "Extra modes for generic mode."  :prefix "generic-"  :group 'generic  :version "20.3")(defcustom generic-extras-enable-list nil  "*List of generic modes to enable by default.Each entry in the list should be a symbol.The variables `generic-define-mswindows-modes' and `generic-define-unix-modes'also affect which generic modes are defined.Please note that if you set this variable after generic-x is loaded,you must reload generic-x to enable the specified modes."  :group 'generic-x  :type  '(repeat sexp)  )(defcustom generic-define-mswindows-modes  (memq system-type (list 'windows-nt 'ms-dos))  "*If non-nil, some MS-Windows specific generic modes will be defined."  :group 'generic-x  :type  'boolean  )(defcustom generic-define-unix-modes  (not (memq system-type (list 'windows-nt 'ms-dos)))  "*If non-nil, some Unix specific generic modes will be defined."  :group 'generic-x  :type  'boolean  )(and generic-define-mswindows-modes    (setq generic-extras-enable-list	  (append (list 'bat-generic-mode 'ini-generic-mode			'inf-generic-mode 'rc-generic-mode			'reg-generic-mode 'rul-generic-mode			'hosts-generic-mode			'apache-conf-generic-mode			'apache-log-generic-mode			)		  generic-extras-enable-list)))(and generic-define-unix-modes     (setq generic-extras-enable-list	   (append (list 'apache-conf-generic-mode			 'apache-log-generic-mode			 'samba-generic-mode			 'hosts-generic-mode  'fvwm-generic-mode			 'x-resource-generic-mode			 'alias-generic-mode			 'inetd-conf-generic-mode			 'etc-services-generic-mode			 'etc-passwd-generic-mode			 'etc-fstab-generic-mode			 )		   generic-extras-enable-list)));;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Generic-modes;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Apache(and (memq 'apache-conf-generic-mode generic-extras-enable-list)(define-generic-mode 'apache-conf-generic-mode   (list ?#)   nil   '(("^\\s-*\\(<.*>\\)"       1 'font-lock-constant-face)     ("^\\(\\sw+\\)\\s-"  1 'font-lock-variable-name-face))   (list "srm\\.conf\\'" "httpd\\.conf\\'" "access\\.conf\\'")   (list    (function     (lambda ()      (setq imenu-generic-expression	    '((nil "^\\([-A-Za-z0-9_]+\\)" 1)	      ("*Directories*" "^\\s-*<Directory\\s-*\\([^>]+\\)>" 1)	      ("*Locations*"   "^\\s-*<Location\\s-*\\([^>]+\\)>" 1)	      ))       )))   "Generic mode for Apache or HTTPD configuration files."))(and (memq 'apache-log-generic-mode generic-extras-enable-list)(define-generic-mode 'apache-log-generic-mode  nil  nil  ;; Hostname ? user date request return-code number-of-bytes  '(("^\\([-a-zA-z0-9.]+\\) - [-A-Za-z]+ \\(\\[.*\\]\\)"     (1 font-lock-constant-face)     (2 font-lock-variable-name-face))    )  (list "access_log\\'")  nil  "Mode for Apache log files"));;; Samba(and (memq 'samba-generic-mode generic-extras-enable-list)(define-generic-mode 'samba-generic-mode   (list ?\; ?#)   nil   '(     ("^\\(\\[.*\\]\\)"   1 'font-lock-constant-face)     ("^\\s-*\\(.+\\)=\\([^\r\n]*\\)"      (1 'font-lock-variable-name-face)      (2 'font-lock-type-face))     )   (list "smb\\.conf\\'")   (list 'generic-bracket-support)   "Generic mode for Samba configuration files."));;; Fvwm;; This is pretty basic. Also, modes for other window managers could;; be defined as well.(and(memq 'fvwm-generic-mode generic-extras-enable-list)(define-generic-mode 'fvwm-generic-mode   (list ?#)   (list    "AddToMenu"    "AddToFunc"    "ButtonStyle"    "EndFunction"    "EndPopup"    "Function"    "IconPath"    "Key"    "ModulePath"    "Mouse"    "PixmapPath"    "Popup"    "Style"    )   nil   (list "\\.fvwmrc\\'" "\\.fvwm2rc\\'")   nil   "Generic mode for FVWM configuration files."));;; X Resource;; I'm pretty sure I've seen an actual mode to do this, but I don't;; think it's standard with Emacs(and (memq 'x-resource-generic-mode generic-extras-enable-list)(define-generic-mode 'x-resource-generic-mode   (list ?!)   nil   '(("^\\([^:\n]+:\\)" 1 'font-lock-variable-name-face))   (list "\\.Xdefaults\\'" "\\.Xresources\\'" "\\.Xenvironment\\'" "\\.ad\\'")   nil   "Generic mode for X Resource configuration files."));;; Hosts(and (memq 'hosts-generic-mode generic-extras-enable-list)(define-generic-mode 'hosts-generic-mode   (list ?#)   (list "localhost")   '(("\\([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\\)" 1 'font-lock-constant-face))   (list "[hH][oO][sS][tT][sS]\\'")   nil   "Generic mode for HOSTS files."));;; Windows INF files(and (memq 'inf-generic-mode generic-extras-enable-list)(define-generic-mode 'inf-generic-mode   (list ?\;)   nil   '(("^\\(\\[.*\\]\\)"   1 'font-lock-constant-face))   (list "\\.[iI][nN][fF]\\'")   (list 'generic-bracket-support)   "Generic mode for MS-Windows INF files."));;; Windows INI files;; Should define escape character as well!(and (memq 'ini-generic-mode generic-extras-enable-list)(define-generic-mode 'ini-generic-mode   (list ?\;)   nil   '(("^\\(\\[.*\\]\\)"   1 'font-lock-constant-face)     ("^\\([^=\n\r]*\\)=\\([^\n\r]*\\)$"      (1 font-lock-function-name-face)      (2 font-lock-variable-name-face)))   (list "\\.[iI][nN][iI]\\'")   (list    (function     (lambda ()       (setq imenu-generic-expression	     '((nil "^\\[\\(.*\\)\\]" 1)	       ("*Variables*" "^\\s-*\\([^=]+\\)\\s-*=" 1)))       )))    "Generic mode for MS-Windows INI files."));;; Windows REG files;;; Unfortunately, Windows 95 and Windows NT have different REG file syntax!(and (memq 'reg-generic-mode generic-extras-enable-list)(define-generic-mode 'reg-generic-mode   '(?\;)   '("key" "classes_root" "REGEDIT" "REGEDIT4")   '(("\\(\\[.*]\\)"     1 'font-lock-constant-face)     ("^\\([^\n\r]*\\)\\s-*="  1 'font-lock-variable-name-face))   '("\\.[rR][eE][gG]\\'")    (list     (function      (lambda ()	(setq imenu-generic-expression	'((nil "^\\s-*\\(.*\\)\\s-*=" 1))))))    "Generic mode for MS-Windows Registry files."));;; DOS/Windows BAT files(if (not (memq 'bat-generic-mode generic-extras-enable-list))    nil(define-generic-mode 'bat-generic-mode    nil    nil    (list     ;; Make this one first in the list, otherwise comments will     ;; be over-written by other variables     (list "^[@ \t]*\\([rR][eE][mM][^\n\r]*\\)" 1 'font-lock-comment-face t)     (list "^[ \t]*\\(::.*\\)"		        1 'font-lock-comment-face t)     (list      "^[@ \t]*\\([bB][rR][eE][aA][kK]\\|[vV][eE][rR][iI][fF][yY]\\)[ \t]+\\([oO]\\([nN]\\|[fF][fF]\\)\\)"      '(1 font-lock-builtin-face)      '(2 font-lock-constant-face t t))     ;; Any text (except ON/OFF) following ECHO is a string.     (list      "^[@ \t]*\\([eE][cC][hH][oO]\\)[ \t]+\\(\\([oO]\\([nN]\\|[fF][fF]\\)\\)\\|\\([^>|\r\n]+\\)\\)"      '(1 font-lock-builtin-face)      '(3 font-lock-constant-face t t)      '(5 font-lock-string-face t t))     ;; These keywords appear as the first word on a line.  (Actually, they     ;; can also appear after "if ..." or "for ..." clause, but since they     ;; are frequently used in simple text, we punt.)     ;; In `generic-bat-mode-setup-function' we make the keywords     ;; case-insensitive     (generic-make-keywords-list      (list       "for"       "if"       )      'font-lock-keyword-face "^[@ \t]*")     ;; These keywords can be anywhere on a line     ;; In `generic-bat-mode-setup-function' we make the keywords     ;; case-insensitive     (generic-make-keywords-list      (list       "do"       "exist"       "errorlevel"       "goto"       "not"       ) 'font-lock-keyword-face)     ;; These are built-in commands.  Only frequently-used ones are listed.     (generic-make-keywords-list      (list       "CALL"	    "call"	 "Call"       "CD"	    "cd"	 "Cd"       "CLS"	    "cls"	 "Cls"       "COPY"	    "copy"	 "Copy"       "DEL"	    "del"	 "Del"       "ECHO"	    "echo"	 "Echo"       "MD"	    "md"	 "Md"       "PATH"	    "path"	 "Path"       "PAUSE"	    "pause"	 "Pause"       "PROMPT"	    "prompt"	 "Prompt"       "RD"	    "rd"	 "Rd"       "REN"	    "ren"	 "Ren"       "SET"	    "set"	 "Set"       "START"	    "start"	 "Start"       "SHIFT"	    "shift"	 "Shift"       ) 'font-lock-builtin-face "[ \t|\n]")     (list "^[ \t]*\\(:\\sw+\\)"         1 'font-lock-function-name-face t)     (list "\\(%\\sw+%\\)"		 1 'font-lock-variable-name-face t)     (list "\\(%[0-9]\\)"		 1 'font-lock-variable-name-face t)     (list "\\(/[^/ \"\t\n]+\\)"	 1 'font-lock-type-face)     (list "[\t ]+\\([+-][^\t\n\" ]+\\)" 1 'font-lock-type-face)     (list "[ \t\n|]\\<\\([gG][oO][tT][oO]\\)\\>[ \t]*\\(\\sw+\\)?"	   '(1 font-lock-keyword-face)	   '(2 font-lock-function-name-face nil t))     (list "[ \t\n|]\\<\\([sS][eE][tT]\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*=?"	   '(1 font-lock-builtin-face)	   '(2 font-lock-variable-name-face t t))     )    (list     "\\.[bB][aA][tT]\\'"     "\\`[cC][oO][nN][fF][iI][gG]\\."     "\\`[aA][uU][tT][oO][eE][xX][eE][cC]\\." )    (list 'generic-bat-mode-setup-function)    "Generic mode for MS-Windows BAT files.")  (defvar bat-generic-mode-syntax-table nil    "Syntax table in use in bat-generic-mode buffers.")  (defvar bat-generic-mode-keymap (make-sparse-keymap)    "Keymap for bet-generic-mode.")  (defun bat-generic-mode-compile ()    "Run the current BAT file in a compilation buffer."    (interactive)    (let ((compilation-buffer-name-function	   (function	    (lambda(ign)	      (concat "*" (buffer-file-name) "*")))	      )	    )      (compile       (concat (w32-shell-name) " -c " (buffer-file-name)))))  (defun bat-generic-mode-run-as-comint ()    "Run the current BAT file in a comint buffer."    (interactive)    (require 'comint)    (let* ((file (buffer-file-name))	   (buf-name (concat "*" file "*")))      (save-excursion	(set-buffer	 (get-buffer-create buf-name))	(erase-buffer)	(comint-mode)	(comint-exec	 buf-name	 file	 (w32-shell-name)	 nil	 (list	  "-c"	  file	  )	 )	(display-buffer buf-name))))  (define-key bat-generic-mode-keymap "\C-c\C-c" 'bat-generic-mode-compile)  ;; Make underscores count as words  (if bat-generic-mode-syntax-table      nil    (setq bat-generic-mode-syntax-table (make-syntax-table))    (modify-syntax-entry ?_  "w"  bat-generic-mode-syntax-table))  ;; bat-generic-mode doesn't use the comment functionality of generic-mode  ;; because it has a three-letter comment-string, so we do it  ;; here manually instead  (defun generic-bat-mode-setup-function ()    (make-local-variable	     'parse-sexp-ignore-comments)    (make-local-variable	     'comment-start)    (make-local-variable	     'comment-start-skip)    (make-local-variable	     'comment-end)    (setq imenu-generic-expression  '((nil "^:\\(\\sw+\\)" 1))	  parse-sexp-ignore-comments t	  comment-end                ""	  comment-start		     "REM "	  comment-start-skip	     "[Rr][Ee][Mm] *"	  )    (set-syntax-table	      bat-generic-mode-syntax-table)    ;; Make keywords case-insensitive    (setq font-lock-defaults (list 'generic-font-lock-defaults nil t))    (use-local-map bat-generic-mode-keymap)    )  );;; Mailagent;; Mailagent is a Unix mail filtering program. Anyone wanna do a generic mode;; for procmail?(and (memq 'mailagent-rules-generic-mode generic-extras-enable-list)(define-generic-mode 'mailagent-rules-generic-mode   (list ?#)   (list "SAVE" "DELETE" "PIPE" "ANNOTATE" "REJECT")   '(("^\\(\\sw+\\)\\s-*="         1 'font-lock-variable-name-face)     ("\\s-/\\([^/]+\\)/[i, \t\n]" 1 'font-lock-constant-face))   (list "\\.rules\\'")   (list 'mailagent-rules-setup-function)   "Mode for Mailagent rules files.")(defun mailagent-rules-setup-function ()   (make-local-variable 'imenu-generic-expression)   (setq imenu-generic-expression	 '((nil "\\s-/\\([^/]+\\)/[i, \t\n]" 1)))) );; Solaris/Sys V prototype files(and (memq 'prototype-generic-mode generic-extras-enable-list)(define-generic-mode 'prototype-generic-mode   (list ?#)   nil   '(     ("^\\([0-9]\\)?\\s-*\\([a-z]\\)\\s-+\\([A-Za-z_]+\\)\\s-+\\([^\n\r]*\\)$"      (2 font-lock-constant-face)      (3 font-lock-keyword-face))     ("^\\([a-z]\\) \\([A-Za-z_]+\\)=\\([^\n\r]*\\)$"      (1 font-lock-constant-face)	  (2 font-lock-keyword-face)	  (3 font-lock-variable-name-face))     ("^\\(!\\s-*\\(search\\|include\\|default\\)\\)\\s-*\\([^\n\r]*\\)$"      (1 font-lock-keyword-face)      (3 font-lock-variable-name-face))     ("^\\(!\\s-*\\sw+\\)=\\([^\n\r]*\\)$"      (1 font-lock-keyword-face)      (2 font-lock-variable-name-face))     )   (list "prototype\\'")   nil   "Mode for Sys V prototype files."));; Solaris/Sys V pkginfo files(and (memq 'pkginfo-generic-mode generic-extras-enable-list)(define-generic-mode 'pkginfo-generic-mode   (list ?#)   nil   '(     ("^\\([A-Za-z_]+\\)=\\([^\n\r]*\\)$"      (1 font-lock-keyword-face)      (2 font-lock-variable-name-face))     )   (list "pkginfo\\'")   nil   "Mode for Sys V pkginfo files."));; Javascript mode;; Includes extra keywords from Armando Singer [asinger@MAIL.COLGATE.EDU](define-generic-mode 'javascript-generic-mode  (list "//")  (list   "break"   "case"   "continue"   "default"   "delete"   "do"   "else"   "export"   "for"   "function"   "if"   "import"   "in"   "new"   "return"   "switch"   "this"   "typeof"   "var"   "void"   "while"   "with"   ;; words reserved for ECMA extensions below   "catch"   "class"   "const"   "debugger"   "enum"   "extends"   "finally"   "super"   "throw"   "try"   ;; Java Keywords reserved by JavaScript   "abstract"   "boolean"   "byte"   "char"   "double"   "false"   "final"   "float"   "goto"   "implements"   "instanceof"   "int"   "interface"   "long"   "native"   "null"   "package"   "private"   "protected"   "public"   "short"   "static"   "synchronized"   "throws"   "transient"   "true"   )  (list   (list "^\\s-*function\\s-+\\([A-Za-z0-9_]+\\)"	  '(1 font-lock-function-name-face))     (list "^\\s-*var\\s-+\\([A-Za-z0-9_]+\\)"	      '(1 font-lock-variable-name-face))     )  (list "\\.js\\'")  (list   (function    (lambda ()      (setq imenu-generic-expression	    '((nil "^function\\s-+\\([A-Za-z0-9_]+\\)" 1)	      ("*Variables*" "^var\\s-+\\([A-Za-z0-9_]+\\)" 1)	      ))      )))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -