all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Zhou Ping" <zhouping_jay@msn.com>
Subject: RE: Graying out the code in "#if 0/#endif" brace?
Date: Wed, 30 Jun 2004 09:00:32 +0800	[thread overview]
Message-ID: <BAY3-DAV266bdVJWrGW0000e363@hotmail.com> (raw)
In-Reply-To: <16601.10875.227184.423243@mail.eng.it>

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:GianUberto.Lauri@eng.it] 
Sent: 2004年6月23日 15:00
To: Zhou Ping
Cc: help-gnu-emacs@gnu.org
Subject: Re: Graying out the code in "#if 0/#endif" brace?

>>>>> "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-30  1: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
2004-06-30  1:00   ` Zhou Ping [this message]
  -- 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

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

  git send-email \
    --in-reply-to=BAY3-DAV266bdVJWrGW0000e363@hotmail.com \
    --to=zhouping_jay@msn.com \
    /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.
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.