From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: Recognizing quotations in message-mode Date: Fri, 11 Dec 2015 00:52:04 +0100 Message-ID: <876105dfq3.fsf@mbork.pl> References: <87bn9yc7h5.fsf@mbork.pl> <874mfp27io.fsf@debian.uxu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1449791562 5933 80.91.229.3 (10 Dec 2015 23:52:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 10 Dec 2015 23:52:42 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 11 00:52:35 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1a7B0k-0002rO-0F for geh-help-gnu-emacs@m.gmane.org; Fri, 11 Dec 2015 00:52:34 +0100 Original-Received: from localhost ([::1]:44939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7B0j-0004PG-E4 for geh-help-gnu-emacs@m.gmane.org; Thu, 10 Dec 2015 18:52:33 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7B0X-0004Ov-S7 for help-gnu-emacs@gnu.org; Thu, 10 Dec 2015 18:52:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a7B0U-0001NC-Jy for help-gnu-emacs@gnu.org; Thu, 10 Dec 2015 18:52:21 -0500 Original-Received: from mail.mojserwer.eu ([2a01:5e00:2:52::8]:52702) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7B0U-0001Mk-DP for help-gnu-emacs@gnu.org; Thu, 10 Dec 2015 18:52:18 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 8F7CC8F201A; Fri, 11 Dec 2015 00:52:07 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lupFlUuwVgAb; Fri, 11 Dec 2015 00:52:05 +0100 (CET) Original-Received: from localhost (unknown [109.232.24.28]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 37C1F8F2017; Fri, 11 Dec 2015 00:52:05 +0100 (CET) User-agent: mu4e 0.9.13; emacs 25.0.50.1 In-reply-to: <874mfp27io.fsf@debian.uxu> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2a01:5e00:2:52::8 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:108358 Archived-At: On 2015-12-11, at 00:44, Emanuel Berg wrote: > Marcin Borkowski writes: > >> Is there a function which, called in message-mode, >> would tell me whether the point is within >> a quotation? > > Because comments in `message-mode' are inserted and > interacted with the same way comments in programming > modes, I thought the downmost code would work. But it > doesn't; perhaps the "syntax" of a message hasn't been > added to, or is incompatible with, the workings of > `syntax-ppss'. > > Anyway, what about this? > > (defun point-in-quotation-p () > (save-excursion > (beginning-of-line) > (string= ">" (thing-at-point 'char t)))) > > You can use `comment-start' if you don't want to > hard-code the ">". Well, I did this: --8<---------------cut here---------------start------------->8--- (defun message-in-quotation-p () "Return t if the point is within a quotation. Use `message-yank-prefix' to determine that." (save-excursion (beginning-of-line) (looking-at-p (concat "^" (regexp-quote message-yank-prefix))))) --8<---------------cut here---------------end--------------->8--- which is more or less what you've suggested. It's not that I can't code this, I just thought that maybe I won't have to reinvent the wheel. And btw, why use `thing-at-point' and not just `char-after'? > Here is the code that didn't work - perhaps some of it > can be brought over to the above code tho, in > particular the interactive stuff. > > (defun point-in-comment-p (&optional print-message) > (interactive "p") > "True iff point is in a comment." > (let*((comment (nth 8 (syntax-ppss))) > (feedback (format "%s comment" (if comment "Yes:" "No"))) ) > (prog1 comment > (when print-message (message feedback)) ))) In my use-case, I don't want interactive stuff - I need that function so that I can count the sentences in an email (excluding quotations). Thanks anyway, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University