help-gnu-emacs
[Top][All Lists]
Advanced

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

RE: Graying out the code in "#if 0/#endif" brace?


From: Zhou Ping
Subject: RE: Graying out the code in "#if 0/#endif" brace?
Date: Wed, 30 Jun 2004 09:00:32 +0800

Thanks! I'm a beginner to emacs and do not understand this code well. Do you
know how to use this code?

Best regards,
Zhou Ping.

-----Original Message-----
From: Gian Uberto Lauri [mailto:address@hidden 
Sent: 2004年6月23日 15:00
To: Zhou Ping
Cc: address@hidden
Subject: Re: Graying out the code in "#if 0/#endif" brace?

>>>>> "ZP" == Zhou Ping <address@hidden> writes:

ZP> Thank you! I'm not familiar with emacs/LISP programming, do you know any

ZP> sample code for reference?

Take a look to the CVS version of the TeX mode or look at this 
(broken) code:

(defvar html-helper-font-lock-syntactic-keywords
  `(("<\\([%?]\\|[a-zA-Z][^>]\\|[!/][a-zA-Z]\\|!--\\)" 1 "\<")))
;;    ("\\([%?a-zA-Z]\\-\\)>" 2 "\>")))


(defun html-helper-font-lock-unfontify-region (beg end)
  (font-lock-default-unfontify-region beg end)
  (while (< beg end)
    (let ((next (next-single-property-change beg 'display nil end))
          (prop (get-text-property beg 'display)))
      (if (and (eq (car-safe prop) 'raise)
               (member (car-safe (cdr prop)) '(-0.3 +0.3))
               (null (cddr prop)))
          (put-text-property beg next 'display nil))
      (setq beg next))))

(defun html-helper-font-lock-last-char-helper ()
  (when (eq (char-syntax (preceding-char)) ?/)
    (put-text-property (1- (point)) (point) 'syntax-table '(1)))
  (unless (eobp)
    (put-text-property (point) (1+ (point)) 'syntax-table '(12))))

(defun html-helper-skip-to-regexp (regexp)
  "Goes past the regexp or to point-max (used by
   html-helper-font-lock-syntactic-face-function"
  (if (re-search-forward regexp nil t)
      (backward-char 2)
    (goto-char (point-max))))

(defun html-helper-font-lock-syntactic-face-function (state)
  (let ((char (nth 3 state)))
    (cond
     ;; char è nil
     (char font-lock-string-face)
     (t
      (set 'char (char-before (point)))
      (cond ((string-match "[a-zA-Z/]" (char-to-string char))
             ;; This is an HTML tag
;            (put-text-property (- (point) 2) 'syntax-table '(11))
             (save-excursion
               (cond ((char-equal ?> (char-after (point)))
                      (put-text-property (point) (1+ (point)) 'syntax-table
'(12)))
                     (t
                      (html-helper-skip-to-regexp "[^?%]>")
                      (html-helper-font-lock-last-char-helper))))
             html-helper-tag-face)
            ((string-match "[%?]"  (char-to-string char))
             ;; This is a server script block
;            (put-text-property (- (point) 2) 'syntax-table '(11))
             (save-excursion
               (html-helper-skip-to-regexp "[%?]>")
               (html-helper-font-lock-last-char-helper))
             html-helper-server-script-face)
            ((char-equal ?! char)
             ;; This is an HTML tag
             (if (char-equal ?- (following-char))
;                (put-text-property (- (point) 2) 'syntax-table '(11))
                 (progn
                   (save-excursion
                     (html-helper-skip-to-regexp "-->")
                     (html-helper-font-lock-last-char-helper))
                   font-lock-comment-face)
                 (progn
                   (save-excursion
                     (html-helper-skip-to-regexp "[^%?]>")
                     (html-helper-font-lock-last-char-helper))
                   html-helper-tag-face)))
            (t
             ;; This is a comment...
             nil))))))

(defun html-helper-mark-sexp ()
  (interactive)
  (let ((here (point))
        (point-open (1+ (point)))
        (point-close (1- (point))))
    (if (not (= 0 (skip-chars-backward "^<")))
        (set 'point-open (1- (point))))
    (if (not (= 0 (skip-chars-forward "^>")))
        (set 'point-close (1+ (point))))
        (goto-char point-open)
    (if (and (<= point-open here)
             (<= here point-close))
        (mark-defun)
      (push-mark here)
      (goto-char here))))

(defun html-helper-tag-beginning-position (&optional inizio)
  "finds the begin of a tag"
  (save-excursion
    (if (not (= 0 (+ (skip-chars-backward "^<")
                     (skip-chars-backward "<"))))
        (point)
      (line-beginning-position inizio))))


-- 
 /\            ___
/___/\__|_|\_|__|___Gian Uberto Lauri_____________________
  //--\ | | \|  |   Integralista GNUslamico e fancazzista 
\/




reply via email to

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