1

I'm trying to get emacs to understand ♥ as punctuation.
(modify-syntax-entry ?♥ "." text-mode-syntax-table)

I'm not sure what the issue is. (That is a unicode heart.)
(modify-syntax-entry ?\u2665 "." text-mode-syntax-table)

For purposes of recognizing that a new sentence starts after "Hi!♥"

How can I troubleshoot this?

Examples:

Lorem impsum dolor.♥ Sit amet.|

(where the pipe indicates the starting cursor position.)
Hitting M-a moves the cursor to the left of "Lorem".

Lorem impsum dolor♥. Sit amet.|

Hitting M-a moves the cursor to the left of "Sit".

I want both cases for it to move to the left of "Sit". In some modes.

4
  • You say nothing about the symptoms of the problem. Provide a recipe or description that shows what the problem is.
    – Drew
    Aug 11, 2020 at 18:56
  • Why has the O.P. used three (3) spaces following the . in the NEWENTRY argument?
    – lawlist
    Aug 11, 2020 at 21:29
  • @lawlist: no idea why, but it does not seem to make any (?) difference - when I look at the character with C-u C-x = it says that the syntax is "punctuation", so the code works. It's not clear why the OP thinks that there is a problem.
    – NickD
    Aug 11, 2020 at 22:18
  • I removed the extra spaces, thank you for that. I added examples of what doesn't work. I was unaware of C-x C-x =, which was one of the troubleshooting features I was fishing for by posting this question, but I also get "punctuation" so I don't know why it doesn't seem to be recognized as such.
    – Sandra
    Aug 12, 2020 at 6:54

1 Answer 1

2

Sentence movement functions use the regexp returned by the (sentence-end) function to find the end of a sentence. The (sentence-end) function returns the value of the sentence-end variable if it is not nil. (The function and variable share the same name).

You can modify the value of the sentence-end variable to any regexp you want. In order to maintain all other functionallity provided by the defaults for sentence movement, I recommend you set the value of sentence-end to be a regexp matching either ♥ or the default return value of the (sentence-end) function.

Below is a function that sets the local value of the sentence-end variable as described.

(defun my-setup-sentence-end ()
   "Modify the local value of the `sentence-end'
variable to be a regexp matching either ♥ or the default
regexp returned by the `sentence-end' function."
   (setq-local
    sentence-end
    (rx (or "♥" (eval (let ((sentence-end nil)) (sentence-end)))))))

Once you have this function you can add it as a hook to any mode you would like.

;; For example, you can add this behavior to `text-mode' like so
(add-hook 'text-mode-hook 'my-setup-sentence-end)

Now you can use (forward-sentence), (backward-sentence) and other text movemnt functions to navigate to ♥ characters. This regexp may not fit your exact use case, but should provide the basic understanding for you to create your own.

Take a look at the paragraph.el source file for more information about the modification of sentence-end.

4
  • Looking at evaluation of (sentence-end), it currently returns "\\([.?!…‽][]\"'”’)}]*\\($\\|[  ]\\)\\|[。.?!]+\\)[   ]*" and I'm not sure how the syntax-table factors into that. So weird! I think I can find a work-around to my problem by modifying sentence-end like you suggest.
    – Sandra
    Aug 12, 2020 at 6:59
  • @Sandra The solution will depend on what you want from the heart character, making emacs know that it's punctuation doesn't mean it will use it as a sentence delimiter and vice versa. What is the use case you're building for? Aug 12, 2020 at 15:27
  • @Sandra Interesting, it looks like that package revolves mainly around the tools from paragraph.el, did this function work in conjunction with that? Aug 13, 2020 at 14:11

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.