[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[eev] escript-mode

From: rubikitch
Subject: [eev] escript-mode
Date: Mon, 11 Jul 2005 17:00:33 -0000

I once created escript-mode.
This major-mode highlights sexp in comment and so on.
But I *failed* to highlights sexp in comment in emacs-lisp-mode...

;;;; [2003/07/27]
;;;; escript-mode by rubikitch <address@hidden>
(defface ee-link-underline
  '((t (:foreground "blue" :underline t))) t)
(setq ee-link-underline (make-face 'ee-link-underline))
(define-derived-mode escript-mode text-mode "ES"
  "major-mode for e-scripts"
  ;; sexp search
  (define-key escript-mode-map "\M-p" 'ee-prev-sexp-in-comment)
  (define-key escript-mode-map "\M-n" 'ee-next-sexp-in-comment)
  (define-key escript-mode-map "\C-c\C-t" 'escript-goto-top-page)
  (define-key escript-mode-map "\C-c\C-c" 'ee-save-sexp-eol)
  (make-local-variable 'font-lock-defaults)
  (make-local-variable 'font-lock-keywords)
  (make-local-variable 'truncate-lines)
  (setq truncate-lines t)

  (make-local-variable 'font-lock-comment-face)
  (setq font-lock-comment-face 'eev-glyph-face-red)

  (setq font-lock-keywords
        '(("^ *#[^\(]+\\((.*)\\)$" 1 ee-link-underline)
          ("^ *\\(#[^\(]+\\)\\((.*)\\)$" 1 font-lock-comment-face)))
  (setq font-lock-defaults '((font-lock-keywords) t nil))  
(add-to-alist 'auto-mode-alist '("\\.e$" . escript-mode))

(make-variable-buffer-local 'escript-top-page)
(defun escript-goto-top-page ()
  (when (boundp 'escript-top-page)
    (find-file escript-top-page)))

;;;; sexp search
(defun ee-next-sexp-sub (re)
  (let ((pt (point)))
    (forward-line 1)
    (unless (re-search-forward re nil t)
      (goto-char pt)
      (error "sexp not found")))
  (search-forward "("))

(defun ee-prev-sexp-sub (re)
  (when (eq (char-before) ?\) )
    (forward-char -1))
  (if (re-search-backward re nil t)
      (goto-char (match-end 0))
    (error "sexp not found"))
  (search-forward "("))

(defun ee-next-sexp ()
  (ee-next-sexp-sub ")$"))
(defun ee-prev-sexp ()
  (ee-prev-sexp-sub ")$"))

;;;; sexp search in comment
(defun ee-sexp-in-comment-regexp ()
  (let ((c (if comment-start
               (substring comment-start 0 1)
    (format "[%s;#].*([A-Za-z].+)$" c)))

(defun ee-next-sexp-in-comment ()
  (ee-next-sexp-sub (ee-sexp-in-comment-regexp)))
(defun ee-prev-sexp-in-comment ()
  (ee-prev-sexp-sub (ee-sexp-in-comment-regexp)))

(global-set-key "\M-F" 'ee-next-sexp-in-comment)
(global-set-key "\M-B" 'ee-prev-sexp-in-comment)
(global-set-key "\M-p" 'ee-prev-sexp-in-comment)
(global-set-key "\M-n" 'ee-next-sexp-in-comment)

;;;; anchor movement
;;;; [2005/06/12] revised
(defun ee-next-anchor ()
  (let ((pt (point)))
    (forward-line 1)
    (unless (re-search-forward (format ee-anchor-format ".+") nil t)
      (goto-char pt)
      (error "anchor not found")))

(defun ee-prev-anchor ()
  (let ((p (point)))
    (when (eq (char-before) (string-to-char (substring ee-anchor-format -1)) )
    (if (re-search-backward (format ee-anchor-format ".+") nil t)
        (goto-char (match-end 0))
      (goto-char p)
      (error "anchor not found")
;; eev anchor
(global-set-key "\M-P" 'ee-prev-anchor)
(global-set-key "\M-N" 'ee-next-anchor)

;; save-sexp
(defvar ee-saved-sexp nil)
(defun ee-save-sexp-eol ()
  (setq ee-saved-sexp (buffer-substring-no-properties (+ (length 
ee-hyperlink-prefix)  (ee-bol)) (ee-eol)))

(defun ee-comment-prefix ()
  (concat (replace-regexp-in-string " +$" "" (or comment-start "#")) " "))

;; replace yank
(defun ee-yank3 (arg)
  (interactive "P")
  (when ee-saved-sexp
    (kill-new (concat (ee-comment-prefix) ee-saved-sexp "\n"))
    (setq ee-saved-sexp nil))
  (yank arg))
(global-set-key "\C-y" 'ee-yank3)

;;;; [2005/06/02] set escript-mode in *Elisp hyperlinks*
(defadvice find-elinks (after escript-mode activate)

;;;; [2005/05/23] set view-mode
(defun view-mode-writable ()
  (view-mode 1)
  (setq buffer-read-only nil))

(defmacro ee-view-mode-writable-advice (f)
  `(defadvice ,f (after read-only activate)

(ee-view-mode-writable-advice find-estring)
(ee-view-mode-writable-advice find-sh)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]