Content AND Presentation

(Note to English-speaking readers: the links entitled Komentarze na tej stronie lead to comment pages.)

2016-02-06 An attachment reminder in mu4e

A nice feature of Gmail is that you can ask it to remind you about attachments if the message contains things like “I attach” and there is no attachment. Some time ago I decided that I want my mu4e to do this, too. (And it seems that I'm far from being the only one.) And here it my take on the subject.

(defun mbork/message-attachment-present-p ()
  "Return t if an attachment is found in the current message."
  (save-excursion
    (save-restriction
      (widen)
      (goto-char (point-min))
      (when (search-forward "<#part" nil t) t))))

(defcustom mbork/message-attachment-intent-re
  (regexp-opt '("I attach"
		"I have attached"
		"I've attached"
		"I have included"
		"I've included"
		"see the attached"
		"see the attachment"
		"attached file"))
  "A regex which - if found in the message, and if there is no
attachment - should launch the no-attachment warning.")

(defcustom mbork/message-attachment-reminder
  "Are you sure you want to send this message without any attachment? "
  "The default question asked when trying to send a message
containing `mbork/message-attachment-intent-re' without an
actual attachment.")

(defun mbork/message-warn-if-no-attachments ()
  "Ask the user if s?he wants to send the message even though
there are no attachments."
  (when (and (save-excursion
	       (save-restriction
		 (widen)
		 (goto-char (point-min))
		 (re-search-forward mbork/message-attachment-intent-re nil t)))
	     (not (mbork/message-attachment-present-p)))
    (unless (y-or-n-p mbork/message-attachment-reminder)
      (keyboard-quit))))

(add-hook 'message-send-hook #'mbork/message-warn-if-no-attachments)

(In fact, it should work in Gnus, too, since I use message-send-hook.)

I admit that the function mbork/message-attachment-present-p is rather crude, but it seems to work fine. I’d gladly hear about why it’s wrong and how to correct it if there are any cases when it might break.

Notice also the use of regexp-opt; it is a convenience function which creates an efficient regex out of a list of strings.

Also, I decided that if the user decides not to send the message, using keyboard-quit is simple and effective – this way I didn’t have to advise any functions (AFAIK, you can’t use message-send-hook to actually prevent sending the message.)

Finally, I’d like to mention that the above code is an excerpt from a library of functions which make writing emails more pleasant. The library is here: https://github.com/mbork/message, it is WiP, and some functions might even not work. (I have a small hiatus now, but I will come back to work on it. Some of its features might even find their way to Emacs some day.)

CategoryEnglish, CategoryBlog, CategoryEmacs

Comments on this page

2016-01-30 Dimming out tildes in AUCTeX

I often write LaTeX in Emacs with AUCTeX. One thing I use a lot is tildes (these little ~ signs, which for LaTeX mean “unbreakable space”). This is justified; first of all, when writing in Polish, which has a few one-letter connectives (like i, which means and) or prepositions (like w, which means in), there is a well-known rule that you shouldn’t left them at the very end of the line. (While there is no such rule for English, I also avoid putting the indefinite preposition a at the end of the line. Probably I’m just trained to consider that ugly; OTOH, it is practically always tied to the next word, so it seems to make sense.) Secondly, when I write about maths (and I do a lot), I don’t like my lines to start with symbols, so I write e.g. things like consider the function~$f$ etc.

The problem with tildes is that they don’t look like spaces, and if you use them a lot, it becomes a bit more difficult to actually read the LaTeX source. There is a way to help with that, though: font-locking (it’s called syntax coloring in modern tools – but Emacs had that before it was cool, in fact even before it got its mainstream name!).

There is one problem with that approach. Font-locking is a messy business. I spent some time skimming through font-latex.el to see whether there exists some knob I could turn for that, but alas, either there isn’t one, or it is well hidden.

Fortunately, there is a universal (i.e., not LaTeX-specific) kind of knob for such things in Emacs: font-lock keywords. Of course, I don’t want my tildes highlighted (actually, dimmed) in modes other than TeX-related ones, so I’ll also need to use a hook.

  (add-hook
   'TeX-mode-hook
   (lambda ()
     (font-lock-add-keywords
      nil
      '(("~" . 'font-latex-sedate-face)))))

Interestingly, the second argument to font-lock-add-keywords is a mode, but most of the time you shouldn’t be using it. As the docstring says, if you use that instead of putting the whole thing in a hook (as above), you will only add your keywords to the mode you specified, not in any derived mode, which is most probably not what you want.

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryTeX, CategoryLaTeX

Comments on this page

2016-01-23 Personal Information Managers – a rant

Some time ago I had this weird experience. A friend of mine wrote on some social media site that his daughter was born that day, and he asked (semi-jokingly, I guess) for wishes next year, for her first birthday. Of course, I immediately put the date into Org-mode, and promptly forgot about it.

One of the things I do every morning is to look at the agenda for the next two weeks. So fourteen days between day zero I started to get reminders. My plan was to write my wishes right after midnight, so that I could claim to be the first one;-).

And of course, since I look at my agenda in the morning, I forgot about it in the evening and went to bed.

Next day I sighed and said to myself, fine, I won’t be the first one, but I’ll send my wishes anyway, of course. And so I did.

After a few hours, I got a response from the friend, who said that he was very surprised to read my message. “Isn’t /gettit your daughter’s birthday today?”, I asked (afraid that I mixed up the dates or something). “Yes it is”, he answered, “but you were the only one to respond to the request I made last year!”.

Ouch.

And this is now bugging me. Why all PIMs, why Org-mode, smartphones, reminders etc., if we don’t spend five seconds entering important things into them?

So I decided to do something about it. I started small, by trying to do what should be done myself: to put important things into my scheduler app (as I said, it’s Org-mode, but this doesn’t matter now). Since this is about treating people as important, I also decided to actually send Christmas postcards to people; I mean, not virtual postcards, but physical ones. Not bought, made by me and my daughter. (For Easter, we’ll make more of those, and we’ll engage the Mommy, too.)

I love technology. But it’s no use if we forget about what’s really important.

Thank you for reading, you can get back to Facebook now.

CategoryEnglish, CategoryBlog, CategoryOrgMode

Comments on this page

More...

(Więcej means More in Polish; click it to see older entries.)

CategoryEnglish, CategoryBlog