* Graying out the code in "#if 0/#endif" brace?
@ 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>
0 siblings, 2 replies; 7+ messages in thread
From: Zhou Ping @ 2004-06-23 0:55 UTC (permalink / raw)
Hello all,
I noticed that vim can use different color on the code enclosed in an "#if
0/#endif" directive brace. This is very useful for code editing or reading.
I wonder if emacs has this kind of feature? If so, how can I add/enable it?
Thanks.
Best regards,
Zhou Ping.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Graying out the code in "#if 0/#endif" brace?
@ 2004-06-23 2:00 Zhou Ping
2004-06-23 7:00 ` Gian Uberto Lauri
0 siblings, 1 reply; 7+ messages in thread
From: Zhou Ping @ 2004-06-23 2:00 UTC (permalink / raw)
Thank you! I'm not familiar with emacs/LISP programming, do you know any
sample code for reference?
Best regards,
Zhou Ping.
= = = Original message = = =
>>>>>"ZP" == Zhou Ping <zhouping_jay@msn.com> writes:
ZP> Hello all,
ZP> I noticed that vim can use different color on the code enclosed in an
"#if
ZP> 0/#endif" directive brace. This is very useful for code editing or
reading.
ZP> I wonder if emacs has this kind of feature? If so, how can I add/enable
it?
ZP> Thanks.
I don't think emacs has this but it's possible to add it, even if I have
some trouble doing something like in another mode I mantain.
The trick is to define #if[ ^I]+0 as a syntactic keyword and write a piece
of code that skips everithyng up to the #endif...
--
/\ ___
/___/\__|_|\_|__|___Gian Uberto Lauri_____________________
//--\ | | \| | Integralista GNUslamico e fancazzista
\/
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Graying out the code in "#if 0/#endif" brace?
2004-06-23 2:00 Zhou Ping
@ 2004-06-23 7:00 ` Gian Uberto Lauri
2004-06-30 1:00 ` Zhou Ping
0 siblings, 1 reply; 7+ messages in thread
From: Gian Uberto Lauri @ 2004-06-23 7:00 UTC (permalink / raw)
Cc: help-gnu-emacs
>>>>> "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
\/
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Graying out the code in "#if 0/#endif" brace?
2004-06-23 7:00 ` Gian Uberto Lauri
@ 2004-06-30 1:00 ` Zhou Ping
0 siblings, 0 replies; 7+ messages in thread
From: Zhou Ping @ 2004-06-30 1:00 UTC (permalink / raw)
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
\/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Graying out the code in "#if 0/#endif" brace?
@ 2004-06-23 0:54 Zhou, Ping A
0 siblings, 0 replies; 7+ messages in thread
From: Zhou, Ping A @ 2004-06-23 0:54 UTC (permalink / raw)
Hello all,
I noticed that vim can use different color on the code enclosed in an
"#if 0/#endif" directive brace. This is very useful for code editing or
reading. I wonder if emacs has this kind of feature? If so, how can I
add/enable it? Thanks.
Best regards,
Zhou Ping.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-06-30 1:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-23 0:55 Graying out the code in "#if 0/#endif" brace? 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
-- strict thread matches above, loose matches on Subject: below --
2004-06-23 2:00 Zhou Ping
2004-06-23 7:00 ` Gian Uberto Lauri
2004-06-30 1:00 ` Zhou Ping
2004-06-23 0:54 Zhou, Ping A
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).