{"id":2955,"date":"2014-09-05T06:46:20","date_gmt":"2014-09-05T10:46:20","guid":{"rendered":"http:\/\/irreal.org\/blog\/?p=2955"},"modified":"2014-09-05T06:46:22","modified_gmt":"2014-09-05T10:46:22","slug":"temporary-syntax-tables-revisited","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=2955","title":{"rendered":"Temporary Syntax Tables Revisited"},"content":{"rendered":"<p> The other day, I wrote about Xah Lee&#8217;s post on <a href=\"http:\/\/irreal.org\/blog\/?p=2945\">temporary syntax tables<\/a> and the <code>with-syntax-table<\/code> macro. Subsequently, Lee discovered a nasty side effect that he wrote about on the <a href=\"https:\/\/plus.google.com\/113859563190964307534\/posts\/WB5r4bg8ifZ\">G+ Emacs Community<\/a> site. The problem was that his code <\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-emacs-lisp\">(<span style=\"color: #a020f0;\">with-syntax-table<\/span> (standard-syntax-table)\n  (modify-syntax-entry ?\\&#171; <span style=\"color: #8b2252;\">\"(&#187;\"<\/span>)\n  (modify-syntax-entry ?\\&#187; <span style=\"color: #8b2252;\">\")&#171;\"<\/span>)\n  <span style=\"color: #b22222;\">;; <\/span><span style=\"color: #b22222;\">&#8230;<\/span>\n  )\n<\/pre>\n<\/p><\/div>\n<p> modified the original standard syntax table for all buffers. <\/p>\n<p> The problem is <code>(standard-syntax-table)<\/code> doesn&#8217;t copy the standard syntax table; it just returns a pointer to the standard syntax table object. This is the same thing that happens if you assign a list to a variable: <\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-emacs-lisp\">(<span style=\"color: #a020f0;\">setq<\/span> x '(1 2 3))\n(<span style=\"color: #a020f0;\">setq<\/span> y x)\n(setf (car y) 5)\n(message <span style=\"color: #8b2252;\">\"x is %s\"<\/span> x)\n<\/pre>\n<\/p><\/div>\n<p> returns <\/p>\n<pre class=\"example\">\nx is (5 2 3)\n<\/pre>\n<p> because <code>x<\/code> and <code>y<\/code> refer to the same object. <\/p>\n<p> What we need to do is first make a copy of the standard syntax table. Happily, the <code>copy-syntax-table<\/code> function does just that<sup><a id=\"fnr.1\" name=\"fnr.1\" class=\"footref\" href=\"#fn.1\">1<\/a><\/sup> so if we evaluate <\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-emacs-lisp\">(<span style=\"color: #a020f0;\">with-syntax-table<\/span> (copy-syntax-table)\n  (modify-syntax-entry ?&#8249; <span style=\"color: #8b2252;\">\"(&#8250;\"<\/span>)\n  (describe-syntax))\n<\/pre>\n<\/p><\/div>\n<p> the \u2039 is described as an open bracket but if we open a new fundamental buffer and call <code>describe-syntax<\/code> it is described as punctuation, as expected. <\/p>\n<p> Lee <a href=\"http:\/\/ergoemacs.org\/emacs\/elisp_modify_syntax_table_temporarily.html\">solved this problem<\/a> by creating a new syntax table with <code>make-syntax-table<\/code> and added his definitions to it. You might think that Lee&#8217;s solution is incorrect because the other syntax definitions will be missing from his new table but it <i>is<\/i> correct because <code>make-syntax-table<\/code> will create a table that inherits from the standard syntax table (or whatever table you specify). <\/p>\n<div id=\"footnotes\">\n<h2 class=\"footnotes\">Footnotes: <\/h2>\n<div id=\"text-footnotes\">\n<div class=\"footdef\"><sup><a id=\"fn.1\" name=\"fn.1\" class=\"footnum\" href=\"#fnr.1\">1<\/a><\/sup> <\/p>\n<p class=\"footpara\"> <code>copy-syntax-table<\/code> copies standard syntax table by default but you can specify a table explicitly if you want to start with some other table. <\/p>\n<\/div><\/div>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The other day, I wrote about Xah Lee&#8217;s post on temporary syntax tables and the with-syntax-table macro. Subsequently, Lee discovered a nasty side effect that he wrote about on the G+ Emacs Community site. The problem was that his code &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=2955\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[18],"class_list":["post-2955","post","type-post","status-publish","format-standard","hentry","category-programming","tag-emacs"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2955"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2955\/revisions"}],"predecessor-version":[{"id":2956,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2955\/revisions\/2956"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}