{"id":6479,"date":"2017-08-07T10:42:00","date_gmt":"2017-08-07T14:42:00","guid":{"rendered":"http:\/\/irreal.org\/blog\/?p=6479"},"modified":"2017-08-07T10:42:07","modified_gmt":"2017-08-07T14:42:07","slug":"counting-words-in-some-buffers-only","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=6479","title":{"rendered":"Counting Words in Some Buffers Only"},"content":{"rendered":"<p> It is often, but not always, nice to have a running count of the words in a buffer. Most usually, this is convenient for writers or students who need to keep track of word count in a paper or book. One way of doing that is the excellent <a href=\"https:\/\/github.com\/bnbeckwith\/wc-mode\">wc-mode<\/a> that I wrote about <a href=\"http:\/\/irreal.org\/blog\/?p=5722\">previously<\/a>. <\/p>\n<p> I like to keep a running count when I&rsquo;m writing a blog post but almost never otherwise. I have a key sequence to turn it on and off so it&rsquo;s easy to enable it for the buffers that I need it in. Still, it got to be a pain to turn it on every time I wrote a post so I added a bit of Elisp to enable it when I open a file in <code>\/Users\/jcs\/org\/blog<\/code>, which is where my blog posts live. <\/p>\n<p> Here&rsquo;s the code, which as you can see, is merely part of the <code>use-package<\/code> call. <\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-emacs-lisp\">(<span style=\"color: #a020f0;\">use-package<\/span> <span style=\"color: #008b8b;\">wc-mode<\/span>\n  <span style=\"color: #483d8b;\">:ensure<\/span> t\n  <span style=\"color: #483d8b;\">:init<\/span>\n  (<span style=\"color: #a020f0;\">add-hook<\/span> 'org-mode-hook\n            (<span style=\"color: #a020f0;\">lambda<\/span> () (<span style=\"color: #a020f0;\">when<\/span> (<span style=\"color: #a020f0;\">and<\/span> (buffer-file-name)\n                                  (string= (file-name-directory (buffer-file-name))\n                                           <span style=\"color: #8b2252;\">\"\/Users\/jcs\/org\/blog\/\"<\/span>))\n                         (wc-mode 1))))\n  <span style=\"color: #483d8b;\">:bind<\/span> (<span style=\"color: #8b2252;\">\"H-=\"<\/span> . wc-mode)\n  <span style=\"color: #483d8b;\">:config<\/span>\n  (wc-mode nil))\n<\/pre>\n<\/div>\n<p> It&rsquo;s important to add the hook in the <code>:init<\/code> section, otherwise it won&rsquo;t work until <code>wc-mode<\/code> is enabled manually at least once. <\/p>\n<p> This is pretty trivial and I wasn&rsquo;t going to write about it but I saw a question on reddit asking how to do something similar so I thought my solution might be useful to someone else. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is often, but not always, nice to have a running count of the words in a buffer. Most usually, this is convenient for writers or students who need to keep track of word count in a paper or book. &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=6479\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[18],"class_list":["post-6479","post","type-post","status-publish","format-standard","hentry","category-general","tag-emacs"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6479"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6479\/revisions"}],"predecessor-version":[{"id":6480,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6479\/revisions\/6480"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}