Content AND Presentation

Last edit

Summary: remove obsolete info about Polish words (they've been translated to English a long time ago anyway).

Deleted:

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

Deleted:

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


2019-01-20 Filling and version control

It has been said a lot of times that when writing some (natural language) text with version control in Emacs, filling is a bad idea. Any change involving adding or deleting a significant number of characters and then refilling can result in all subsequent lines in a paragraph changed, and the diff looks really ugly then.

The solution usually proposed is putting each sentence on a separate line, and then just use visual-line-mode to wrap your lines on the screen without putting any hard newlines in.

Well, I sort of dislike this idea. The main problem I have with it is that I either tend to write rather longish sentences myself, or work on texts by other people that have long sentences. (This is definitely not optimal with respect to readability etc., but I’ve been working in academia for the past 14 years, and old habits die hard.) Having a wide screen makes visual-line-mode rather uncomfortable (well, I could try longlines-mode, which is deprecated, but reported to work – maybe some day), and looking at diffs with long lines is a pain in the neck anyway.

It occurred to me that one possible solution is to try to have the best of both worlds. Why not fill the paragraph, but introducing a newline after each sentence, too? (After writing this, I realized that I’m definitely neither the only one, not the first one to have this idea.) Then, when a change is large enough to “spill over” to next lines, it will only affect the current sentence, which seems to me an acceptable compromise. Here’s my attempt at the code which you could bind to M-q or some other key:

(defun fill-sentences-in-paragraph ()
  "Fill the current paragraph with a newline after each sentence."
  (interactive)
  (save-excursion
    (save-restriction
      (mark-paragraph)
      (narrow-to-region (point) (mark))
      (while (not (eobp))
	(fill-region-as-paragraph
	 (point)
	 (progn (forward-sentence) (point)))
	(delete-horizontal-space)
	(newline)))))

It is a quick-and-dirty solution (as many other Emacs hacks are), but I plan to start to use it and if there are any problems, I might refine them over time.

And now that I think about it, why not highlight long sentences as I write them? This would be a cool aid when writing prose. And Emacs already has the infrastructure to do that, like flymake. After a quick search, it turns out that I am (obviously) again not the first one to come up with that idea; it turns out that there are quite a few linters for English, and even one that works for more languages, including my mother tongue. So one of the future blog posts of mine will probably be a survey of these tools.

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryTeX

Comments on this page

2019-01-14 Some Org Agenda keybindings

This post is just a friendly reminder that it may be a good idea to look in the manual from time to time, just in case there are some gems hidden there you don’t remember (even if you read it once).

It turns out that you can do a lot of things from the Org Agenda buffer. Usually, I just wander around that buffer using the normal movement commands and exit it using q. Of course, I also often mark things done using t and jump to them using RET. But until recently, that was about it.

It turns out Agenda can do a lot more. One nice thing is C-c C-o, which just opens the link from the selected entry (and displays a list of links found there first if there is more than one). f and b move forward and backward in time, and . gets back to today. A number of commands starting with v changes the appearance of the agenda, showing or hiding various kinds of information.

If you have a habit of not closing your agenda (e.g., with q), you might find M-<up> and M-<down> useful – they allow to rearrange the order of agenda entries, but only temporarily (until the agenda is (re)generated again).

If you want to reschedule your tasks, S-<right>, S-<left> and > may be for you.

You can also manage clocks (i.e., start and stop clocking etc.) from the agenda view.

One of the cooler things you can do in the agenda is bulk actions. You can mark more than one entry (manually or with a regex) and then perform some action on all marked entries. The available actions include manipulating todo state, tagging, archiving, scheduling/deadlining and refiling. You may also, as the manual puts is, “[r]eschedule randomly into the coming N days”, which I never used, but that looks cool. If that weren’t enough, defining custom actions is (of course) also possible, either on the fly or permanently.

Do yourself a favor and check out the manual, there are even more possibilities!

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryOrgMode

Comments on this page

2019-01-06 Emacs server and other Emacs instances

A few years ago, I mentioned indirectly that I use emacs-server. For some time, I just had (emacs-server) in my init.el. This, however, had an annoying side effect of giving an error when I started a second instance of Emacs. (I do this from time to time, e.g. when I fiddle with my config, to check whether the changes in init.el made in the “main” instance of Emacs are working.) Then I changed it to

(ignore-errors
  (emacs-server))

which didn’t really matter, since what (emacs-server) issues is a warning, not an error. Finally, I decided to do something better about it. I changed my invocation of emacs-server to something like this.

(require 'server)
(unless (server-running-p)
  (server-start))

Actually, this is not the whole story. In the rare case I have two Emacsen running at the same time, I usually treat one of them as temporary. Why not make this fact more prominent? At the same time, quitting the “temporary” one can (and should) be easier. So I installed this.

(require 'server)
(if (server-running-p)
    (load-theme 'green-phosphor t)
  (setq confirm-kill-emacs #'yes-or-no-p)
  (server-start)
  (global-set-key (kbd "C-x C-3") 'server-edit))

I installed a second color theme just so the temporary Emacs can look very different, and I deliberately chose a venomous one. (Don’t get me wrong, I like green; when I play a boardgame, I choose green pieces whenever I can, since it’s my favorite color. But an intense green instead of something more subdued is probably not the best choice for your editor.) Also, I moved (setq confirm-kill-emacs #'yes-or-no-p) and (global-set-key (kbd "C-x C-3") 'server-edit) into the else-branch of the if so that they are activated only in my main Emacs. (By the way, I’ve had a setup where Emacs is started automatically after I log in for quite a few years now. It doesn’t make much sense to turn on a computer without starting the OS, right? ;-) )

CategoryEnglish, CategoryBlog, CategoryEmacs

Comments on this page

More...

CategoryEnglish, CategoryBlog