all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Recognizing quotations in message-mode
@ 2015-12-10 21:35 Marcin Borkowski
  2015-12-10 23:44 ` Emanuel Berg
  0 siblings, 1 reply; 4+ messages in thread
From: Marcin Borkowski @ 2015-12-10 21:35 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list

Hi all,

Is there a function which, called in message-mode, would tell me whether
the point is within a quotation?

TIA,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



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

* Re: Recognizing quotations in message-mode
  2015-12-10 21:35 Recognizing quotations in message-mode Marcin Borkowski
@ 2015-12-10 23:44 ` Emanuel Berg
  2015-12-10 23:52   ` Marcin Borkowski
  0 siblings, 1 reply; 4+ messages in thread
From: Emanuel Berg @ 2015-12-10 23:44 UTC (permalink / raw)
  To: help-gnu-emacs

Marcin Borkowski <mbork@mbork.pl> 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 ">".

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)) )))

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: Recognizing quotations in message-mode
  2015-12-10 23:44 ` Emanuel Berg
@ 2015-12-10 23:52   ` Marcin Borkowski
  2015-12-11  0:54     ` Emanuel Berg
  0 siblings, 1 reply; 4+ messages in thread
From: Marcin Borkowski @ 2015-12-10 23:52 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs


On 2015-12-11, at 00:44, Emanuel Berg <embe8573@student.uu.se> wrote:

> Marcin Borkowski <mbork@mbork.pl> 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



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

* Re: Recognizing quotations in message-mode
  2015-12-10 23:52   ` Marcin Borkowski
@ 2015-12-11  0:54     ` Emanuel Berg
  0 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2015-12-11  0:54 UTC (permalink / raw)
  To: help-gnu-emacs

Marcin Borkowski <mbork@mbork.pl> writes:

> Well, I did this ... 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.

Why not? Perhaps this time a"round" you'll discover
something new. The wheel isn't that simple. Beware tho
the hub, the rim, the brake arm and more are all
already "spoke"n for.

> And btw, why use `thing-at-point' and not just
> `char-after'?

Because then you don't have to use the
`save-excursion' and `beginning-of-line' stuff.
Compare:

(defun point-in-quotation-p ()
  (= ?\> (char-after (point-at-bol)) ))

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

end of thread, other threads:[~2015-12-11  0:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-10 21:35 Recognizing quotations in message-mode Marcin Borkowski
2015-12-10 23:44 ` Emanuel Berg
2015-12-10 23:52   ` Marcin Borkowski
2015-12-11  0:54     ` Emanuel Berg

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.