unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: GianUberto.Lauri@eng.it (Gian Uberto Lauri)
Cc: help-gnu-emacs@gnu.org
Subject: Re: Graying out the code in "#if 0/#endif" brace?
Date: Wed, 23 Jun 2004 09:00:11 +0200	[thread overview]
Message-ID: <16601.10875.227184.423243@mail.eng.it> (raw)
In-Reply-To: <BAY3-F3RLPdiJxO7rPv0001b184@hotmail.com>

>>>>> "ZP" == Zhou Ping <zhouping_jay@msn.com> 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	other threads:[~2004-06-23  7:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-23  2:00 Graying out the code in "#if 0/#endif" brace? Zhou Ping
2004-06-23  7:00 ` Gian Uberto Lauri [this message]
2004-06-30  1:00   ` Zhou Ping
  -- strict thread matches above, loose matches on Subject: below --
2004-06-23  0:55 Zhou Ping
2004-06-23  1:19 ` Gian Uberto Lauri
     [not found] ` <mailman.1187.1088266061.1953.help-gnu-emacs@gnu.org>
2004-06-29 20:25   ` David Kastrup
2004-06-23  0:54 Zhou, Ping A

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16601.10875.227184.423243@mail.eng.it \
    --to=gianuberto.lauri@eng.it \
    --cc=help-gnu-emacs@gnu.org \
    --cc=saint@eng.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).