Strona domowa Ostatnie zmiany Wiara Matematyka TeX Blog Varia O mnie English

Strona domowa

Witam na mojej prywatnej stronie internetowej!

[If this is all Polish to you, click here: English]

Uwaga: z oczywistych powodów nie mogę zagwarantować swojej nieomylności, choć staram się o zgodność tego, co piszę, z Prawdą. Jest również oczywiste, że nie gwarantuję takiej zgodności w przypadku komentarzy. Umieszczenie linku do strony spoza niniejszego serwisu nie musi oznaczać, że podzielam poglądy autora tej strony, a jedynie, że uważam ją za wartościową z takich czy innych powodów.

Marcin ‘mbork’ Borkowski

2014-10-28 Single vs double spaces

Now don’t get me wrong: I have nothing personal against those strange people who end their sentences with a single space, I just want them locked in some place so they don’t interfere with us normals. But reality is reality, and after I found that I'm not the only one being angry with the one-spacers sending me their crippled files, I decided to do something about it. This is really a ten minute hack and a proof of concept rather than a full solution, but what about this?

(defvar sentence-end-double-space-threshold 2
  "How many occurrences of \".  \" per kilobyte should be enough
  to declare this file as using two spaces after sentences.")

(defun set-sentence-end-double-space ()
  "Set `sentence-end-double-space' according to how often the
  literal string \".  \" occurs in the current buffer."
  (make-local-variable 'sentence-end-double-space)
  (if (>= (* (count-matches "\\.  ") 1024)
	  (* (buffer-size) sentence-end-double-space-threshold))
      (setq sentence-end-double-space t)
    (setq sentence-end-double-space nil)))

(add-hook 'find-file-hook 'set-sentence-end-double-space)	  

Now when you open a file, Emacs decides (using the very conservative value of sentence-end-double-space-threshold, which you can setq to whatever you feel right) which style it is. (Obviously, this does not help in case of pasting from the browser or whatever. It could be done, advising yank and – if needed – replacing spaces in the yanked text as necessary, but hey, I only had 15 minutes for that!)

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryHumor

Komentarze na tej stronie

Więcej...