all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* creating customized major mode - emacs 23.4.1
@ 2012-05-28 10:38 Janssen, Kurt H.
  2012-05-29 11:20 ` Tassilo Horn
  0 siblings, 1 reply; 2+ messages in thread
From: Janssen, Kurt H. @ 2012-05-28 10:38 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org


[-- Attachment #1.1: Type: text/plain, Size: 1411 bytes --]

I am attempting to create a major mode for simple syntax highlighting.
I have created the attached disco-mode.el file and and put (load "~/.emacs.d/disco-mode.el") in my init.el file.
I have text files whose first line is,
 -*- dicso -*-
but I do not get any text highlighting (sample txt file attached)?

I am running Redhat 5.2 and using the following version of emacs,

GNU Emacs 23.4.1 (x86_64-unknown-linux-gnu, Motif Version 2.3.0)

Any help would be appreciated.

thanks


________________________________

The contents of this email, including all related responses, files and attachments transmitted with it (collectively referred to as "this Email"), are intended solely for the use of the individual/entity to whom/which they are addressed, and may contain confidential and/or legally privileged information. This Email may not be disclosed or forwarded to anyone else without authorization from the originator of this Email. If you have received this Email in error, please notify the sender immediately and delete all copies from your system. Please note that the views or opinions presented in this Email are those of the author and may not necessarily represent those of Saudi Aramco. The recipient should check this Email and any attachments for the presence of any viruses. Saudi Aramco accepts no liability for any damage caused by any virus/error transmitted by this Email.

[-- Attachment #1.2: Type: text/html, Size: 4020 bytes --]

[-- Attachment #2: disco-mode.el --]
[-- Type: application/octet-stream, Size: 16278 bytes --]

;;; disco-mode.el --- major mode for editing Disco configuration files

;; Keywords:	languages, faces
;; Author:	Robert Nader  <naderra@aramco.com.sa> or
;; Last edit:	07-Jan-01     <robert_nader@yahoo.com>
;; Last edit:	07-Mar-11     <kevin.erickson@aramco.com>

;; Credits: Jonathan Marten  <jonathan.marten@uk.sun.com> or
;;                           <jjm@keelhaul.demon.co.uk>
;; for providing me with sendmail-mode.el to and suggesting to
;; use it as a template for creating this disco-mode

;; This file is an add-on for XEmacs or GNU Emacs (not tested with the latter).
;;
;; It 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.
;;
;; It 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 your copy of 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:
;;
;; Disco configuration files are usually pretty unintelligible, so
;; some help with syntax colouring and comment indentation is always
;; welcome.  This mode attempts to do that.
;;
;; The fontification rules and the list of keywords were derived from
;; the DISCO manuals and the online documentation included with the
;; latest versions of DISCO.  They may be neither complete nor 100%
;; accurate; since the configuration file syntax is not particularly
;; rigourous or consistent a totally accurate fontification might not
;; be possible.  However, it has been tested on as many configuration
;; files as I could find, from a number of systems and of various
;; vintages.  Additional keywords or examples of incorrect fontification
;; or comment indentation would be most welcome.
;;
;; Syntactic fontification is done, but only for quoted strings.
;;
;; No comment syntax is defined, because Emacs' built-in indentation and
;; fontification cannot handle the varying rules for placement and
;; validity of comments, especially with the differences between pre-V8
;; and later disco.  Comments are fontified using the font-lock
;; regexps, and comment indentation is handled specially using
;; `disco-indent-for-comment'.  This is because the syntax of a comment,
;; or even whether one is allowed at all, varies depending on what sort of
;; line the comment is on and the version of the configuration file.  The
;; only particularly complex case is for an "R" line, where the comment
;; has no delimiter but is separated from the RHS by at least one tab.
;; We have to take care that there is at least that one tab here, even
;; in the case where the indent is past the comment column and normally
;; only a single space would be inserted.
;;
;; All brackets ("[]", "<>", "()" and "{}") are normally considered
;; worthy of matching.  However, "<>" sometimes leads to anomalous
;; indications because "$>" does not have a matching open "<".  This
;; should be fixed in paren.el by not considering a character to be
;; a paren if the character preceding it has char-quote syntax
;; ("/" in syntax table).  In this mode, "$" has such syntax.
;;
;; There is no indentation in the configuration file, so (contrary to the
;; usual Emacs convention), the TAB key is defined to self-insert.
;;
;; Disco is very sensitive to the format of the configuration file, and
;; small and sometimes invisible errors can cause serious problems.  This
;; mode attempts to help as far as is possible:
;;
;; 1.  Additional spaces before or after tabs, and lines containing only
;;     whitespace, are highlighted.  This can help to avoid unintended
;;     addition of whitespace tokens and continuation lines.
;;
;; 2.  DISCO requires a final newline in the configuration file,
;;     otherwise the last line of the file is silently ignored.  This is
;;     enforced by ensuring that `require-final-newline' is forced to
;;     "add always" if it is set to "never" by default.  If the setting is
;;     "ask" then it stays.

;;; Change Log:
;;
;; Version 1.0, June 1999	First public release
;;
;; Version 1.01, October 1999	Eliminated a redundant 'progn'!
;;				Properly define mode hook variable
;; Version 1.02, March, 2011	Added additional keywords to be highlighted

;;; To do:
;;
;; 1.  Detect the version of the configuration file and set the V8 option
;;     automatically.
;;
;; 2.  How about a command to take the configuration file and run address
;;     tests, disco debugging, etc. in a subprocess?
;;
;; 3.  The font-lock regexps could possibly be optimised some more.
;;
;; 4.  Is it a good approach to use `indent-for-comment' and then fix up the
;;     results afterwards?  It may be better to do all the work here.


;;; Code:

;; Requires
(require 'regexp-opt)


;; Custom
(defgroup disco-mode nil
  "Disco mode customizations"
  :group 'tools
  :prefix "disco-")

(defcustom disco-allow-v8-comments t
  "*If non-nil, allow comments on all command lines (as with V8 disco).
If nil, comments are only allowed on R lines (without A), standalone lines,
and on S and P command lines (with A)."
  :type 'boolean
  :group 'disco-mode)

(defcustom disco-mode-hook nil
  "*List of hook functions run by `disco-mode' (see `run-hooks')."
  :type 'hook
  :group 'disco-mode)

;; Other variables
; (defvar disco-mode-commands "CDFHKMOPRSTV"
(defvar disco-mode-commands "\*"
  "Disco configuration file commands which may start a line.")

(defvar disco-mode-v8-comment-commands disco-mode-commands
  "Disco configuration file commands which may have a comment in V8 disco.")

(defvar disco-mode-non-v8-comment-commands "PS"
  "Disco configuration file commands which may have a comment in non-V8 disco.")

(defvar disco-mode-map nil
  "Keymap used in Disco mode buffers")

(defvar disco-mode-syntax-table nil
  "Syntax table used in Disco mode buffers")

;(defvar disco-mode-comment-start "A " ; COMMENT
(defvar disco-mode-comment-start "\\*\\* " ; COMMENT
  "String used to insert a new Disco mode comment (except on an R line).")

;(defvar disco-mode-comment-start-skip "A[ \t]+" ; COMMENT
(defvar disco-mode-comment-start-skip "\\*\\*[ \t]+" ; COMMENT
  "Regexp to match a Disco mode comment and everything up to its body (except
on an R line).")

(defvar disco-mode-r-comment-start-skip "^\\(R[^\t\n]+\t+[^\t\n]+\t+\\)"
  "Regexp to match a Disco mode comment and everything up to its body
on an R line.")


;; Faces
(defface disco-space-face                            ; copied from make-mode.el
  '((((class color))
     (:background "hotpink"))
    (((background light))
      (:background "black"))
    (((background dark))
      (:background "white")))
  "Face to use for highlighting misplaced spaces and blank lines in Disco mode."
  :group 'disco-mode)


;; Font lock
(defconst disco-font-lock-keywords
  (purecopy
   (list
    '("^[ \t]+$" 0 disco-space-face)                 ; white lines can cause trouble
    '("\\( +\\)\t" 1 disco-space-face)               ; as can spaces around tabs
    '("\t\\( +\\)" 1 disco-space-face)               ;

    (list (eval-when-compile                            ; keywords
            (concat
             "\\W\\("
             (regexp-opt '("JOB" "job"
			   "CALL" "call"
			   "END" "end"
			   "ALT" "alt"
			   "IF" "if"
			   "IFR" "ifr"
			   "ELSEIF" "elseif"
			   "ENDIF" "endif"
			   "RESET" "reset"
			   "HOLDIF" "holdif"
			   "RECALL" "recall"
			   "PARAM" "param"
			   "INCLUDE" "include"
			   "UNIXCMD" "unixcmd"
			   "\[Uu\]\[Nn\]\[Ii\]\[Xx\]\[Cc\]\[Mm\]\[Dd\]"
			   "[Uu][Nn][Ii][Xx][Cc][Mm][Dd]"
                           "dequote" "host" "dbm" "btree" "hash" "nis"
                           "strict" "mime" "pass8"
                           "check_relay" "check_mail" "check_rcpt" "check_compat" 
                           "client_addr" "client_name" "client_port" 
                           "USAGE" "NOUSER" "NOHOST" "UNAVAILABLE" "SOFTWARE" 
                           "TEMPFAIL" "PROTOCOL" "CONFIG" 
                           "local" "prog"
                           "none" "add-to" "add-apparently-to" "add-to-undisclosed" 
                           "add-bcc"
                           "public" "needmailhelo" "needexpnhelo" "noexpn" 
                           "needvrfyhelo" "novrfy" "restrictmailq" "restrictqrun" 
                           "noreceipts" "goaway" "authwarnings" 
                           "debug" "aaonly" "usevc" "primary" "igntc" "recurse" 
                           "defnames" "stayopen" "dnsrch" "HasWildcardMX"))
             "\\|"
             (mapconcat 'identity (list "[Ff]alse" "[Tt]rue"
                                        (regexp-quote "[IPC]")
                                        (regexp-quote "[TCP]")
                                        (regexp-quote "[LPC]")
                                        (regexp-quote "*file*")
                                        (regexp-quote "*include*")) "\\|")
             "\\)\\W"))
          1 'font-lock-keyword-face nil)

    (list (concat "^[" disco-mode-commands "]")      ; line commands
      0 'font-lock-keyword-face)

    '("^[TV]\\(.+\\)$"                                  ; strings (user/version)
      1 'font-lock-string-face)

    '("^H\\(\\?.\\?\\)?\\(.+\\):"                       ; headers
      2 'font-lock-function-name-face)

    '("^[SM]\\(.*?\\)\\>"                               ; definition (ruleset or mailer)
      1 'font-lock-function-name-face)

    '("^[OP]\\W*\\(.+\\)="                              ; definition (P and new-style O)
      (1 'font-lock-function-name-face)
      ("=\\(.+\\)$" nil nil (1 'font-lock-string-face)))


; -------------------------------------------------------------------
;;    '("^[CDF]{\\(.+?\\)}"                               ; definition (with braces)

    '("^CALL{.*}"                               ; definition (with braces)
      (1 'font-lock-function-name-face)
      ("\\s-+\\(.+\\)$" nil nil (1 'font-lock-string-face)))
; -------------------------------------------------------------------
;;    '("^[CDFO]\\([^{ ]\\)"                              ; definition (CDF and old-style O)
    '("^CALL\\(.*\\)"                              ; definition (CDF and old-style O)
      (1 'font-lock-function-name-face)
      (".+$" nil nil (0 'font-lock-string-face)))
; -------------------------------------------------------------------

    '("^K\\(\\w+\\)\\W+\\(\\w+\\)"                      ; database
      (1 'font-lock-function-name-face)
      (2 'font-lock-keyword-face t))

    '("\\$[=?&~]?\\(?:{\\w+}\\|\\S-\\)"                 ; variables (char or word)
      0 'font-lock-variable-name-face t)

    '("\\$[#>]\\(?:\\w.*?\\|\\s-+\\w+?\\)\\>"           ; variables ($# and $>)
      0 'font-lock-reference-face t)

;EKXRAN    '("\\(^\\|[^$]\\)\\(#.*\\)$"                        ; comments (line or appended)
;    '("\\(^\\|[^$]\\)\\(A.*\\)$"                        ; comments (line or appended) ; COMMENT
    '("\\(^\\|[^$]\\)\\(\\*\\*.*\\)$"                        ; comments (line or appended) ; COMMENT
      2 'font-lock-comment-face t)

    (list (concat disco-mode-r-comment-start-skip    ; comments (after 2nd tab)
                  "\\(.*\\)$")
          2 'font-lock-comment-face t)))
  "Expressions to highlight in Disco mode buffers.")

(put 'disco-mode 'font-lock-defaults '(disco-font-lock-keywords nil nil))


;; Syntax table
(unless disco-mode-syntax-table
  (setq disco-mode-syntax-table (copy-syntax-table nil))
  (modify-syntax-entry ?\   " "     disco-mode-syntax-table)
  (modify-syntax-entry ?\t  " "     disco-mode-syntax-table)
  (modify-syntax-entry ?\f  " "     disco-mode-syntax-table)
  (modify-syntax-entry ?\r  " "     disco-mode-syntax-table)
  (modify-syntax-entry ?\n  " "     disco-mode-syntax-table)
  (modify-syntax-entry ?\_  "w"     disco-mode-syntax-table)
  (modify-syntax-entry ?\-  "w"     disco-mode-syntax-table)
  (modify-syntax-entry ?\(  "()"    disco-mode-syntax-table)
  (modify-syntax-entry ?\)  ")("    disco-mode-syntax-table)
  (modify-syntax-entry ?\[  "(]"    disco-mode-syntax-table)
  (modify-syntax-entry ?\]  ")["    disco-mode-syntax-table)
  (modify-syntax-entry ?\<  "(>"    disco-mode-syntax-table)
  (modify-syntax-entry ?\>  ")<"    disco-mode-syntax-table)
  (modify-syntax-entry ?\{  "(}"    disco-mode-syntax-table)
  (modify-syntax-entry ?\}  "){"    disco-mode-syntax-table)
  (modify-syntax-entry ?\"  "\""    disco-mode-syntax-table)
  (modify-syntax-entry ?\#  "."     disco-mode-syntax-table)
  (modify-syntax-entry ?\$  "/"     disco-mode-syntax-table)
  (modify-syntax-entry ?\\  "/"     disco-mode-syntax-table)
  (modify-syntax-entry ?\,  "."     disco-mode-syntax-table))


;; Keymap
(unless disco-mode-map
  (setq disco-mode-map (make-sparse-keymap))
  (define-key disco-mode-map [(meta \;)] 'disco-indent-for-comment)
  (define-key disco-mode-map [(tab)] 'self-insert-command))


;;;###autoload
(defun disco-mode ()
  "Major mode for editing Disco configuration files.

\\{disco-mode-map}

\\[disco-mode] runs the hook `disco-mode-hook', if that is non-nil."
  (interactive)
  (kill-all-local-variables)
  (use-local-map disco-mode-map)
  (set-syntax-table disco-mode-syntax-table)
  (make-local-variable 'comment-start)
  (setq comment-start nil)
  (make-local-variable 'comment-end)
  (setq comment-end nil)
  (make-local-variable 'comment-start-skip)
  (setq comment-start-skip nil)
  (make-local-variable 'comment-column)
  (setq comment-column 48)
  (and (eq require-final-newline nil)
       (make-variable-buffer-local 'require-final-newline)
       (setq require-final-newline t))
  (setq mode-name "Disco")
  (setq major-mode 'disco-mode)
  (run-hooks 'disco-mode-hook))


(defun disco-indent-for-comment ()
  "Indent this line's comment to comment column, or insert an empty comment.
A comment may or may not be permitted, depending on context and the setting
of `disco-allow-v8-comments'."
  (interactive "*")
  (let (empty comment this)
    (save-excursion
      (beginning-of-line)
      (setq empty (looking-at "\\s-*$"))
;; EKXRAN      (setq comment (looking-at "\\s-*#"))
;      (setq comment (looking-at "\\s-*A")) ;; COMMENT
      (setq comment (looking-at "\\s-*\\*\\*")) ;; COMMENT
      (setq this (char-after)))

    (cond
     ((or empty comment)                                ; empty or comment line
      (beginning-of-line)
      (delete-horizontal-space)
      (unless comment (insert disco-mode-comment-start)))

     ((eq this ?R)                                      ; rule line
      (let ((comment-start-skip disco-mode-r-comment-start-skip)
            (comment-start "")
            (indent-tabs-mode t))
        (indent-for-comment)
        (skip-chars-forward "\t")
        (if (> (current-column) comment-column)         ; past normal comment indent
            (if (not (eq (char-before) ?\ ))
                (if (not (looking-at "[\t\n]")) (insert "\t"))
              (delete-backward-char 1)                  ; must have a tab there
              (insert "\t")))))

     ((string-match (regexp-quote (char-to-string this)) ; command line
                    (if disco-allow-v8-comments disco-mode-v8-comment-commands
                      disco-mode-non-v8-comment-commands))
      (let ((comment-start disco-mode-comment-start)
            (comment-start-skip disco-mode-comment-start-skip))
        (indent-for-comment)))

     (t                                                 ; anything else
      (error "Can't have a comment here")))))


;; Provides
(provide 'disco-mode)

;;; disco-mode.el ends here

[-- Attachment #3: discofile.txt --]
[-- Type: text/plain, Size: 729 bytes --]

** -*- disco -*-
**-----*-------*-------*-------*-------*-------*-------*-------*
** wadi1 - submit in BIGMEM job queue
**  - all cdps at one time
**-----*-------*-------*-------*-------*-------*-------*-------*
*JOB    304902993D
**-----*-------*-------*-------*-------*-------*-------*-------*
*CALL   DUMIN   4
**-----*-------*-------*-------*-------*-------*-------*-------*
*CALL   WADI    7       50              3       0
FILLIM  cwasc1
FILAMP  /data/s99/shdn004/shdn004_30490299/WARE/cwasc1
SDBFILE cwadi1  cwadi1  cwadi1  cwadi1
TERMS   1       2       3       4
****   *CMP    *SHOT   *RECSTAT*OFFSET  order of solution in amp decomp
**-----*-------*-------*-------*-------*-------*-------*-------*
*END

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: creating customized major mode - emacs 23.4.1
  2012-05-28 10:38 creating customized major mode - emacs 23.4.1 Janssen, Kurt H.
@ 2012-05-29 11:20 ` Tassilo Horn
  0 siblings, 0 replies; 2+ messages in thread
From: Tassilo Horn @ 2012-05-29 11:20 UTC (permalink / raw)
  To: help-gnu-emacs

"Janssen, Kurt H." <kurt.janssen@aramco.com> writes:

> I have text files whose first line is,
>  -*- dicso -*-
> but I do not get any text highlighting (sample txt file attached)?

I think that line should look like this (assuming # is the comment
starter in that mode):

# -*- mode: dicso -*-

Alternatively, you can add something like this near the end of the file:

# Local Variables:
# mode: dicso
# End:

Have a look at (info "(emacs)Specifying File Variables").

Bye,
Tassilo




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-05-29 11:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-28 10:38 creating customized major mode - emacs 23.4.1 Janssen, Kurt H.
2012-05-29 11:20 ` Tassilo Horn

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.