all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
Subject: RE: info faces for strings and quotations
Date: Thu, 7 Oct 2004 22:13:06 -0700	[thread overview]
Message-ID: <MEEKKIABFKKDFJMPIOEBIELBCGAA.drew.adams@oracle.com> (raw)
In-Reply-To: <jwvacuysbte.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 3022 bytes --]

This version works well. The fontify function is in line below; the full
patch is attached. This seems to do everything the previous version did,
plus treat initial \" correctly. Things like this from (ccmode)Indentation
Functions are not highlighted now, which is the correct behavior: (\"Hello
world!\");

Thanks to everyone who contributed suggestions. I went with David's
suggestion for treating initial \".

Per Luc's suggestion, I added a note to the doc string of
`Info-fontify-quotations-flag' explaining that fontification can never be
100% reliable, that occasional inappropriate highlighting is not a bug, and
that highlighting can be turned off. It is now off by default.

I won't be working any more on this. I think it is ready for prime time, and
I hope the decision will be to add it to Emacs.

BTW, with this highlighting, I noticed these additional Info text bugs (the
first one I had noticed earlier, but forgot to point out):

 - (eintr)the-the -- "the' should be "the"
 - (gnus)Fancy Mail Splitting: (any "mypackage@somewhere\" -
"bugs-mypackage" "mypkg.list") -- I'm guessing that the backslash doesn't
belong here.
 - (elisp)Specification List -- `(spec .  [(more specs...)])') -- ' is in
wrong place.

 - Drew

;; The regexp has these parts: double-quoted string or single-quoted stuff.
;;
;; String has, inside "...", zero or more of these characters:
;;   - any character except \ and "
;;   - \ followed by any character
;;
;; Single-quoted stuff has, inside `...': any character except '
;;
;; The regexp matches `...' or "...". The latter case also includes
;; pseudo-strings that start with \". The second branch of the
;; conditional tests this: if that is the match, then it moves past
;; the \.
(defun info-fontify-quotations ()
  "Fontify text between double-quotes (\"...\") and single-quotes (`...')
For single-quotes, use face `info-quoted-name'.
For double-quotes, use face `info-string'."
  (while (re-search-forward             ; Match `...' or "..."
          "\"\\(?:[^\\\"]\\|\\\\\\(?:.\\|[\n]\\)\\)*\"\\|`[^']+'"
          nil t)
    (cond ((eq ?` (aref (match-string 0) 0))
           (put-text-property (1+ (match-beginning 0)) (1- (match-end 0))
                              'font-lock-face 'info-quoted-name))
          ((and (goto-char (match-beginning 0)) ; "...": If preceded by \,
skip it
                (= 1 (mod (save-excursion (skip-chars-backward "\\\\")) 2)))
           (forward-char 1))
          ((goto-char (match-end 0))    ; "..." not preceded by \
           (put-text-property (match-beginning 0) (match-end 0)
                              'font-lock-face 'info-string)))))


-----Original Message-----From: Stefan, quoting David, replying to Stefan
> If you don't need regexps, it is usually quite faster just to check with
> (zerop (mod (save-excursion (skip-chars-backward "\\\\")) 2)) whether you
> have an even number of preceding backslashes.

That's true.  The "\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*" prefix can slow down
regexp searching significantly.

[-- Attachment #2: diff-info-highlight-quotations-fourth.txt --]
[-- Type: text/plain, Size: 4215 bytes --]

diff -c "c:/emacs-21.3.50/lisp/info.el" "c:/drews-lisp-20/info-w-quotes-fourth.el"
*** c:/emacs-21.3.50/lisp/info.el	Mon Jul 26 09:42:06 2004
--- c:/drews-lisp-20/info-w-quotes-fourth.el	Thu Oct  7 21:30:04 2004
***************
*** 65,70 ****
--- 65,94 ----
  The Lisp code is executed when the node is selected.")
  (put 'Info-enable-active-nodes 'risky-local-variable t)
  
+ (defcustom Info-fontify-quotations-flag nil
+   "*Non-nil means `info' fontifies text between quotes.
+ This applies to double-quote strings (\"...\") and text between
+ single-quotes (`...').
+ 
+ Note: This fontification can never be 100% reliable. It aims to
+ be useful in most Info texts, but it can occasionally result in
+ fontification that you might not expect. This is not a bug; it is
+ part of the design to be able to appropriately fontify a great
+ variety of texts. Set this flag to nil if you do not find this
+ fontification useful."
+   :type 'boolean
+   :group 'info)
+ 
+ (defface info-quoted-name               ; For `...'
+   '((t (:inherit font-lock-constant-face)))
+   "Face used for quoted names (`...') in `info'."
+   :group 'info)
+ 
+ (defface info-string                    ; For "..."
+   '((t (:inherit font-lock-string-face)))
+   "Face used for strings (\"...\") in `info'."
+   :group 'info)
+ 
  (defface info-node
    '((((class color) (background light)) :foreground "brown" :weight bold :slant italic)
      (((class color) (background dark)) :foreground "white" :weight bold :slant italic)
***************
*** 3416,3421 ****
--- 3440,3449 ----
                (skip-chars-backward " \t,")
                (put-text-property (point) header-end 'invisible t)))))
  
+       ;; Fontify `...' and "..."
+       (goto-char (point-min))
+       (when Info-fontify-quotations-flag (info-fontify-quotations))
+ 
        ;; Fontify titles
        (goto-char (point-min))
        (when not-fontified-p
***************
*** 3669,3676 ****
                                 '(font-lock-face info-xref
                                                  mouse-face highlight
                                                  help-echo "mouse-2: go to this URL"))))
- 
        (set-buffer-modified-p nil))))
  \f
  
  ;; When an Info buffer is killed, make sure the associated tags buffer
--- 3697,3733 ----
                                 '(font-lock-face info-xref
                                                  mouse-face highlight
                                                  help-echo "mouse-2: go to this URL"))))
        (set-buffer-modified-p nil))))
+ 
+ 
+ ;; The regexp has these parts: double-quoted string or single-quoted stuff.
+ ;;
+ ;; String has, inside "...", zero or more of these characters:
+ ;;   - any character except \ and "
+ ;;   - \ followed by any character
+ ;;
+ ;; Single-quoted stuff has, inside `...': any character except '
+ ;;
+ ;; The regexp matches `...' or "...". The latter case also includes
+ ;; pseudo-strings that start with \". The second branch of the
+ ;; conditional tests this: if that is the match, then it moves past
+ ;; the \.
+ (defun info-fontify-quotations ()
+   "Fontify text between double-quotes (\"...\") and single-quotes (`...')
+ For single-quotes, use face `info-quoted-name'.
+ For double-quotes, use face `info-string'."
+   (while (re-search-forward             ; Match `...' or "..."
+           "\"\\(?:[^\\\"]\\|\\\\\\(?:.\\|[\n]\\)\\)*\"\\|`[^']+'"
+           nil t)
+     (cond ((eq ?` (aref (match-string 0) 0))
+            (put-text-property (1+ (match-beginning 0)) (1- (match-end 0))
+                               'font-lock-face 'info-quoted-name))
+           ((and (goto-char (match-beginning 0)) ; "...": If preceded by \, skip it
+                 (= 1 (mod (save-excursion (skip-chars-backward "\\\\")) 2)))
+            (forward-char 1))
+           ((goto-char (match-end 0))    ; "..." not preceded by \
+            (put-text-property (match-beginning 0) (match-end 0)
+                               'font-lock-face 'info-string)))))
  \f
  
  ;; When an Info buffer is killed, make sure the associated tags buffer

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

  reply	other threads:[~2004-10-08  5:13 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-03  7:05 info faces for strings and quotations Drew Adams
2004-10-05  7:15 ` Drew Adams
2004-10-05  7:30   ` Miles Bader
2004-10-06  8:34     ` Matt Hodges
2004-10-05  8:58   ` Drew Adams
2004-10-05 11:43     ` Stefan
2004-10-05 11:56   ` Stefan
2004-10-05 16:11     ` Drew Adams
2004-10-06  2:25       ` Luc Teirlinck
2004-10-06  4:19         ` Drew Adams
2004-10-06  4:28           ` Miles Bader
2004-10-06  7:40             ` Drew Adams
2004-10-06 21:32               ` Drew Adams
2004-10-06  4:53           ` Stefan Monnier
2004-10-06  7:07             ` Drew Adams
2004-10-06 17:07               ` Robert J. Chassell
2004-10-06 21:36                 ` Drew Adams
2004-10-07  5:53                 ` Juri Linkov
2004-10-07  6:53                   ` Drew Adams
2004-10-07 14:58                     ` Stefan Monnier
2004-10-07 15:13                       ` David Kastrup
2004-10-07 17:01                         ` Stefan Monnier
2004-10-08  5:13                           ` Drew Adams [this message]
2004-10-07 15:13                       ` Kim F. Storm
2004-10-07 16:35                         ` David Kastrup
2004-10-08  0:33                   ` Luc Teirlinck
2004-10-08 16:04                   ` Richard Stallman
2004-10-08 16:51                     ` Luc Teirlinck
2004-10-09 15:45                       ` Richard Stallman
2004-10-08 20:00                     ` Robert J. Chassell
2004-10-07  5:57               ` Juri Linkov
2004-10-07 15:22               ` w3 mode Camm Maguire
2004-10-07 17:03                 ` Stefan Monnier
2004-10-07 17:25                   ` Camm Maguire
2004-10-07 17:37                     ` Mark Plaksin
2004-10-07 17:45                     ` Kevin Rodgers
2004-10-08 16:05                 ` Richard Stallman
2004-10-08 17:44                   ` David Kastrup
2004-10-07 15:28               ` unexec development Camm Maguire
2004-10-15 14:10                 ` Camm Maguire
2004-10-15 14:35                   ` Jan D.
2004-10-15 21:11                     ` Camm Maguire
2004-10-16 13:52                   ` Richard Stallman
2004-10-06  8:44         ` info faces for strings and quotations Oliver Scholz
2004-10-07  5:55       ` Juri Linkov
2004-10-07  7:13         ` Drew Adams
  -- strict thread matches above, loose matches on Subject: below --
2004-10-05 16:15 LENNART BORGMAN
2004-10-05 16:28 ` Drew Adams

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=MEEKKIABFKKDFJMPIOEBIELBCGAA.drew.adams@oracle.com \
    --to=drew.adams@oracle.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.