bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#25903: Question re syntax tables and unexpected behaviour in C/C++ m


From: Peter Milliken
Subject: bug#25903: Question re syntax tables and unexpected behaviour in C/C++ major mode
Date: Wed, 1 Mar 2017 09:04:05 +1100

I tried asking this question in gnu.emacs.help but obviously didn't attract the attention of the correct person/people. Hopefully somebody on this list can help.

My code is intended to work as a minor mode with any (programming) major mode (I am actually re-writing a minor mode that I wrote back when Emacs was still at version 19 - a lot has changed since then :-)).

I want to be able to search through a buffer to detect text within {}/[] pairings - and nothing else. I could use regexp searches of course, but I thought it would be a good learning opportunity to use syntax tables (and the forward/backward-sexp functions). 


My code works fine in buffers that have Python, Ada and Lisp major modes but it experiences difficulties in buffers with C/C++ major mode. Basically, when in a C/C++ buffer, the code locates text within "<>" pairs as well as "{}"/"[]" pairs.  I really don't want my code to have an (ugly) exception case where it tests "if in C/C++ mode then check if <> has been detected and skip over them and continue looking for {}/[] pairs"

My code copies the default syntax table, changing every entry to be a word-constituent and then adding the appropriate open parenthesis characters i.e. 

(defvar my-syntax-table (copy-syntax-table (standard-syntax-table))) 

(modify-syntax-entry (cons 0 (max-char)) "w" my-syntax-table)

(modify-syntax-entry ?\{ "(}" my-syntax-table) 
(modify-syntax-entry ?\} "){" my-syntax-table) 
(modify-syntax-entry ?[ "(]" my-syntax-table) 
(modify-syntax-entry ?] ")[" my-syntax-table) 

my code then starts with: 

(with-syntax-table my-syntax-table 
  . 
  . 
  . 



I have checked the "<", ">" entries in the syntax table when running in a buffer with C/C++ and the aref returns (2)  which I believe is the code for a word-constituent, so something in the C/C++ mode must be affecting the sexp functions, but I have no idea what it could be or how to isolate it. 

Any help/clarification would be appreciated - thanks 

Peter 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]