[Top][All Lists]

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

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

From: Gian Uberto Lauri
Subject: Re: Graying out the code in "#if 0/#endif" brace?
Date: Wed, 23 Jun 2004 09:00:11 +0200

>>>>> "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
  (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)))
     ;; char รจ nil
     (char font-lock-string-face)
      (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))
               (cond ((char-equal ?> (char-after (point)))
                      (put-text-property (point) (1+ (point)) 'syntax-table 
                      (html-helper-skip-to-regexp "[^?%]>")
            ((string-match "[%?]"  (char-to-string char))
             ;; This is a server script block
;            (put-text-property (- (point) 2) 'syntax-table '(11))
               (html-helper-skip-to-regexp "[%?]>")
            ((char-equal ?! char)
             ;; This is an HTML tag
             (if (char-equal ?- (following-char))
;                (put-text-property (- (point) 2) 'syntax-table '(11))
                     (html-helper-skip-to-regexp "-->")
                     (html-helper-skip-to-regexp "[^%?]>")
             ;; This is a comment...

(defun html-helper-mark-sexp ()
  (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))
      (push-mark here)
      (goto-char here))))

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

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

reply via email to

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