1

In some of my query-replecements I need to have only alphabetic characters as word constituents in a local defined syntax-table. My approach is this:

(with-syntax-table
   (let ((my-syntax-table (make-syntax-table latex-mode-syntax-table)))
     (modify-syntax-entry '(48 . 57) "_" my-syntax-table)
 ;; "_" = symbol constituent
 ;; '(48 . 57) = 0, 1, 2 ... 9

     (set-syntax-table my-syntax-table)
     (perform-replace "\\w+" "word" t t nil 1 nil (point-min) (point-max))

     ))

How can find which other characters are word-constituents in latex-mode-syntax-table?

EDIT. I wrote this loop:

(setq CHAR 0)
(while (<= CHAR 255)
(when (string-match-p "119" (prin1-to-string (char-syntax CHAR)))
  (insert (char-to-string CHAR) "\s"))
(setq CHAR (1+ CHAR))

That returns (after setting latex-mode):

0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z ¥ · À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ø ù ú û ü ý þ ÿ

So I was wondering if there is another way to set only the alphabetic characters instead of unset the other ones.

1

I think that the loop of the edited version of my question solved my problem. I want to share here the solution temporarily adopted. I'd like to know if there is something better (e.g. a more compact or elegant solution):

(defvar my-syntax-table
  (let ((table (make-syntax-table latex-mode-syntax-table)))
    (modify-syntax-entry '0 "_" table)           ; "_" = symbol constituent
    (modify-syntax-entry '39 "_" table)          ; '
    (modify-syntax-entry '(48 . 57) "_" table)   ; 0--9
    (modify-syntax-entry '(128 . 255) "_" table) 
    table))

(with-syntax-table my-syntax-table
  (perform-replace "\\w+" "word" t t nil 1 nil (point-min) (point-max))
  )

EDIT. I finally adopted the following solution to find which chars are class-c in a syntax-table:

(defun returnClassChars (CLASS SYNTAX_TABLE)
  "Classes:
-   whitespace character        /   character quote character
w   word constituent            $   paired delimiter
_   symbol constituent          '   expression prefix
.   punctuation character       <   comment starter
(   open delimiter character    >   comment ender
)   close delimiter character   !   generic comment delimiter
\"  string quote character      |   generic string delimiter
\\   escape character            @   inherit from \"standard-syntax-table\"'
"
  (with-output-to-temp-buffer "*Chars*"
    (princ (with-temp-buffer
         (with-syntax-table SYNTAX_TABLE
           (setq CHAR 0)
           (while (<= CHAR 255)
         (when (= (string-to-char CLASS)  (char-syntax CHAR))
           (insert (prin1-to-string CHAR) "\t" (char-to-string CHAR) "\n") )
         (setq CHAR (1+ CHAR))))
         (buffer-string)))))
  • 1
    To my knowledge, there is no reason to set-syntax-table when using with-syntax-table. (with-syntax-table my-syntax-table ...) The whole idea when using with-syntax-table is to have a temporary syntax table for the duration of the function call. There may be benefit that I am not aware of to using (make-char-table 'syntax-table nil), but I am accustomed to seeing make-syntax-table instead. – lawlist Jul 4 '17 at 15:53
  • @lawlist You're right. I'll correct my post. – Gabriele Nicolardi Jul 4 '17 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.