From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Help Understanding syntax-propertize-function Date: Mon, 15 Mar 2021 21:42:38 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13370"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Reza Nikoopour Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Mar 16 02:43:55 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lLykV-0003OF-OY for ged-emacs-devel@m.gmane-mx.org; Tue, 16 Mar 2021 02:43:55 +0100 Original-Received: from localhost ([::1]:58314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLykU-0003lx-Qh for ged-emacs-devel@m.gmane-mx.org; Mon, 15 Mar 2021 21:43:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLyjN-0003KD-TA for emacs-devel@gnu.org; Mon, 15 Mar 2021 21:42:45 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:22552) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLyjL-0003rp-72 for emacs-devel@gnu.org; Mon, 15 Mar 2021 21:42:44 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 6F70D80C41; Mon, 15 Mar 2021 21:42:41 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id DCD1F8063A; Mon, 15 Mar 2021 21:42:39 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1615858959; bh=zVVD5Gus61LCzqNp7hoL82hYb+ll/l3k7PTdGhTmSvE=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=dHfU7oPg8nbk1nqgjxj2kNtBrBmGlhbitF2ZmhTYEWedrYYMCDK1wMVxBIsERUWCO c2XcTNK9ODRJfKjmgEzQwx53BL4elewagAoHdP4Z4XU4ALIw7u7rGc6tnlFhyZh0Ua ZM/uofk2Q0y/1KVhU74riffAa9zAvxPJw+rMjVrBjH+/4TCkofLgU/8iao5edraNrq bEZ0G10FkaJrOmLElf0+gG5fQelnQEGhLG/M/K7vLATpKKmtBQesxFlvdRfEH2e4t3 HIp7dAgpoRTjfsI2O0AYn3eUfvejFXcIMCX2PgGtypKOMhY5nv/Cp6vtZaw7N16yhj hjRoHpvo4t7FA== Original-Received: from alfajor (unknown [216.154.43.249]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id AE00A120348; Mon, 15 Mar 2021 21:42:39 -0400 (EDT) In-Reply-To: (Reza Nikoopour's message of "Mon, 15 Mar 2021 16:58:41 -0700") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:266490 Archived-At: > I'm struggling to understand what `hcl--syntax-propertize-heredoc` is > doing. > Could you provide a high level explanation like you did with > `hcl--syntax-propertize-function`. > That helped me a lot. > (defun hcl--syntax-propertize-heredoc (end) The purpose of the function is to do the "syntax-propertize" of the inside of a heredoc. It presumes that point *may* be in a heredoc but not necessarily. > (let ((ppss (syntax-ppss))) > (when (eq t (nth 3 ppss)) Here we fetched the syntax state at point and then we checked that we are indeed inside a heredoc (or at least a "string like thing" that was opened using the `|` syntax category; in this mode should should only ever happen if we have placed this syntax because we found a heredoc marker). > (let ((key (get-text-property (nth 8 ppss) 'hcl-here-doc-marker)) This fetches the string that was used in the heredoc opener and which has to be used as heredoc closer. It's been placed on the opening char at position (nth 8 ppss) by the same code that placed the `|` syntax property on that same character. > (case-fold-search nil)) I guess here that the code does that because HCL defines the heredoc marker to be case-significant. > (when (re-search-forward > (concat "^\\(?:[ \t]*\\)" (regexp-quote key) "\\(\n\\)") > end 'move) Here we look for the heredoc end marker. If we can't find one before `end`, it just means that the heredoc extends further and hence we have nothing to do (we could actually remove/override any `|` syntax that might appear before `end` in case such a thing is possible, but apparently the rest of code is arranged so that this is not needed). > (let ((eol (match-beginning 1))) > (put-text-property eol (1+ eol) > 'syntax-table (string-to-syntax "|")))))))) If we did find the heredoc end marker before `end`, then we mark it as being the end by adding the `|` syntax to the ending character. Stefan