From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Luc Teirlinck Newsgroups: gmane.emacs.bugs Subject: confusion over undocumented syntax-table features, font-lock and syntax-tables Date: Wed, 12 Feb 2003 21:43:21 -0600 (CST) Sender: bug-gnu-emacs-bounces+gnu-bug-gnu-emacs=m.gmane.org@gnu.org Message-ID: <200302130343.VAA10097@eel.dms.auburn.edu> NNTP-Posting-Host: main.gmane.org X-Trace: main.gmane.org 1045107837 10447 80.91.224.249 (13 Feb 2003 03:43:57 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 13 Feb 2003 03:43:57 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18jAFX-0002bh-00 for ; Thu, 13 Feb 2003 04:41:23 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18jAHL-0000v3-04 for gnu-bug-gnu-emacs@m.gmane.org; Wed, 12 Feb 2003 22:43:15 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18jAH5-0000VC-00 for bug-gnu-emacs@gnu.org; Wed, 12 Feb 2003 22:42:59 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18jAGi-0007h0-00 for bug-gnu-emacs@gnu.org; Wed, 12 Feb 2003 22:42:40 -0500 Original-Received: from manatee.dms.auburn.edu ([131.204.53.104]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18jAGf-0007Sm-00 for bug-gnu-emacs@gnu.org; Wed, 12 Feb 2003 22:42:33 -0500 Original-Received: from eel.dms.auburn.edu (eel.dms.auburn.edu [131.204.53.108]) by manatee.dms.auburn.edu (8.9.1a/8.9.1) with ESMTP id VAA29629; Wed, 12 Feb 2003 21:42:31 -0600 (CST) Original-Received: (from teirllm@localhost) by eel.dms.auburn.edu (8.9.3+Sun/8.9.3) id VAA10097; Wed, 12 Feb 2003 21:43:21 -0600 (CST) X-Authentication-Warning: eel.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f Original-To: Matthew Swift X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: bug-gnu-emacs-bounces+gnu-bug-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.bugs:4446 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:4446 Matthew Smith wrote: The results of the following code completely baffles me. Is global-font-lock-mode changing the syntax classes? Yes, using syntax text properties, and it is impossible to get the correct shell syntax without such text properties. (However does anybody understand the behavior of char-syntax in the ielm run below???) Did you specify which shell you are using? If it is bash, then # starts a comment at the beginning of a word, elsewhere it has symbol syntax. I was observing a strange behavior in `sh-mode' defined in sh-script.el where (re-search-forward "\\s<\\s<") was failing even though it was passing over a buffer substring of two characters whose syntax classes, as reported by `(char-syntax (char-after N))' and N+1 was "<". I do not know how you possibly can get two consecutive characters with comment-start syntax in bash. (I do not know about other shells.) I cut out the "test file" you included (see below) and put point at the beginning of the line: ## boln is at buffer position 40 Then I ran ielm (for convenience, if you prefer, ypu can use M-:). The result shows the (correcting) influence of font-lock-mode: (Ran using: emacs-21.3.50 -q --no-site-file --eval '(blink-cursor-mode 0)' & This is today's CVS.) Remember that, in the syntax-after return values, 3 stands for symbol, 11 for comment-start. ===File ~/shellsyntax======================================= *** Welcome to IELM *** Type (describe-mode) for help. ELISP> (set-buffer "testfile.sh") ;; ielm specific code # ELISP> (current-buffer) # ELISP> (point) 40 ELISP> parse-sexp-ignore-comments t ELISP> (string (char-syntax (point))) "(" ;; goes completely over my head ELISP> (string (char-syntax (1+ (point)))) ")" ;; this too ELISP> (get-char-property (point) 'syntax-table) nil ELISP> (get-char-property (1+ (point)) 'syntax-table) nil ELISP> (syntax-after (point)) (11) ;; I understand this. ELISP> (syntax-after (1+ (point))) (11) ;; This too, even though it is wrong. ELISP> (global-font-lock-mode 1) t ELISP> (string (char-syntax (point))) "(" ;; ??? ELISP> (string (char-syntax (1+ (point)))) ")" ;; ??? ELISP> (get-char-property (point) 'syntax-table) nil ELISP> (get-char-property (1+ (point)) 'syntax-table) (3) ;; font-lock-mode to the rescue ELISP> (syntax-after (point)) (11) ELISP> (syntax-after (1+ (point))) (3) ;; correct: the second # has symbol syntax, ;; it does not start a comment. ELISP> sh-shell bash ELISP> sh-shell-file "/usr/local/bin/bash" ELISP> (string (char-syntax ?#)) "<" ;; I undestand this too, but how does this rhyme with the above??? ELISP> ============================================================ Do not ask me to explain the char-syntax behavior. I have no clue. Sincerely, Luc. Appendix: Test file used: -----cut here (setq test " hello () { echo world.; } ## boln is at buffer position 40 ") (defun test () (sh-mode) (message "result is %S" (if (and (equal "<" (char-to-string (char-syntax ?#))) (equal (char-after 40) ?#) (equal (char-after 41) ?#) (equal "<" (char-to-string (char-syntax (char-after 40)))) (equal "<" (char-to-string (char-syntax (char-after 41)))) ) (save-excursion (goto-char (point-min)) (re-search-forward "\\s<\\s<")) "whoops!"))) (progn (global-font-lock-mode 0) ;; succeeds (test)) (progn (global-font-lock-mode 1) ;; `re-search-forward' fails the SECOND time, if not the first (no ;; pattern found) (test)) ;;(sh-mode) ;;(emacs-lisp-mode) ;;(global-font-lock-mode) ;;(test) ---- end of test file