all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#25903: Question re syntax tables and unexpected behaviour in C/C++ major mode
@ 2017-02-28 22:04 Peter Milliken
  2017-03-02  4:32 ` Glenn Morris
  2017-03-02  4:49 ` npostavs
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Milliken @ 2017-02-28 22:04 UTC (permalink / raw)
  To: 25903

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

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

[-- Attachment #2: Type: text/html, Size: 5270 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-02 20:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-28 22:04 bug#25903: Question re syntax tables and unexpected behaviour in C/C++ major mode Peter Milliken
2017-03-02  4:32 ` Glenn Morris
2017-03-02  4:49 ` npostavs
2017-03-02 20:10   ` Alan Mackenzie

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.