From 38adb8d0ac6eebbeb5e26d2095526c3ba9459d7a Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sun, 24 Nov 2013 23:04:18 +0100 Subject: [PATCH] Add blog posts --- articles/c-d_to_close_eshell.org | 56 +++++++++++++++++ articles/mounting_music_dir_before_mpd.org | 44 +++++++++++++ articles/python-mixins.org | 72 ++++++++++++++++++++++ articles/rlwrapping_sbcl.org | 18 ++++++ articles/some_quick_git_diff_tips.org | 56 +++++++++++++++++ blog.org | 45 ++++++++++++++ index.org | 30 ++++++--- org.css | 33 +++++++++- project.el | 15 ++++- 9 files changed, 358 insertions(+), 11 deletions(-) create mode 100644 articles/c-d_to_close_eshell.org create mode 100644 articles/mounting_music_dir_before_mpd.org create mode 100644 articles/python-mixins.org create mode 100644 articles/rlwrapping_sbcl.org create mode 100644 articles/some_quick_git_diff_tips.org create mode 100644 blog.org diff --git a/articles/c-d_to_close_eshell.org b/articles/c-d_to_close_eshell.org new file mode 100644 index 0000000..525e462 --- /dev/null +++ b/articles/c-d_to_close_eshell.org @@ -0,0 +1,56 @@ +#+TITLE: C-d to close eshell + +One of the "tricks" that I have learned to use when working with +terminals is using ~C-d~ to close them, or when working on a TTY +logout. It somehow grew to the extent that if I can't use it, I get +annoyed, like with ~eshell~. + +I have customized ~ansi-term~ to immediately close its buffer after the +shell quits. This makes it very easy to start an ~ansi-term~, which I've +bound to ~C-c t~, run a quick command (perhaps ~make~, or similar), ~C-d~, +and I'm out. I want that for my ~eshell~ too. + +There are a few conditions that I want met before the buffer is +killed, though. + +1. Since ~eshell~ is an Emacs mode like any other, ~C-d~ is usually used + to forward-kill characters, I don't want to lose this. +2. I only want it to quit when the line of input is empty. + +The following piece of code make sure these conditions are met. + +1. It interactively calls =delete-char=, which keeps keybindings like + ~C-4 C-d~ to delete 4 characters working. +2. It catches the error condition which is signaled whenever + =delete-char= can't do it's job (like when there's nothing left to + delete in the buffer). +3. It checks to make sure that the signaled error is the =end-of-buffer= + error. I don't want to kill the buffer if I try to delete more + characters than are in the buffer because I feel that could cause + irritating surprises. +4. It checks of the cursor is at the ~eshell~ prompt. This, combined + with only responding to the =end-of-buffer= error, makes sure we're + on an empty line and not just at the end of the input. Sometimes + keys are pressed at the wrong time and I don't want to have to + re-type a command just because I was being an idiot. +5. If the right conditions aren't met, signal the error again so I can + see what's going on. + +#+BEGIN_SRC emacs-lisp + (defun eshell-C-d () + "Either call `delete-char' interactively or quit." + (interactive) + (condition-case err + (call-interactively #'delete-char) + (error (if (and (eq (car err) 'end-of-buffer) + (looking-back eshell-prompt-regexp)) + (kill-buffer) + (signal (car err) (cdr err)))))) +#+END_SRC + +I then bind this to =C-d= in eshell. + +#+BEGIN_SRC emacs-lisp + (add-hook 'eshell-mode-hook + (lambda () (local-set-key (kbd "C-d") #'eshell-C-d))) +#+END_SRC diff --git a/articles/mounting_music_dir_before_mpd.org b/articles/mounting_music_dir_before_mpd.org new file mode 100644 index 0000000..da9918f --- /dev/null +++ b/articles/mounting_music_dir_before_mpd.org @@ -0,0 +1,44 @@ +#+TITLE: +#+OPTIONS: toc:nil c:t +#+HTML_LINK_UP: ../blog.html + +* Mounting music dir before MPD :systemd:mpd:conf: + +Systemd allows you to specify a program to run before running the main +daemon (or program) with =ExecStartPre=. This can, for instance, be used +to run a mount command before starting ~mpd~. By adding under the +=[Service]= heading: + +#+BEGIN_SRC conf-unix + ExecStartPre=/usr/bin/mount /mnt/music +#+END_SRC + +Now I have already setup my ~fstab~ to know what to mount on ~/mnt/music~, +but of course that shouldn't be necessary. According to the +~systemd.service(5)~ man page it uses the same syntax as =ExecStart=, +which tells us that one must use absolute file names since no shell is +used to start them. + +This also has the effect of stopping the =ExecStart= part from the +~.service~ from being executed if the =ExecStartPre= doesn't finish +successfully. Which works out great in my case as I don't want to +start ~mpd~ if my music directory didn't mount. If you want to ignore +the exit status of (one of) the =ExecStartPre= commands you can prefix +it with a ~-~, for example: + +#+BEGIN_SRC conf-unix + ExecStartPre=-/usr/bin/mount /mnt/music +#+END_SRC + +Which would continue running the =ExecStart= even if mounting failed. + +Also know that there can be multiple =ExecStartPre= options and they +will be executed serially, so for example: + +#+BEGIN_SRC conf-unix + ExecStartPre=/usr/bin/mount /mnt/music + ExecStartPre=-/usr/bin/mount /mnt/music2 +#+END_SRC + +This would fail if ~/mnt/music~ doesn't mount, but would continue just +fine if ~/mnt/music~ did and ~/mnt/music2~ didn't. diff --git a/articles/python-mixins.org b/articles/python-mixins.org new file mode 100644 index 0000000..2c388f1 --- /dev/null +++ b/articles/python-mixins.org @@ -0,0 +1,72 @@ +#+TITLE: Python mixins +#+TAGS: python,coding + +I learned something fun the other day. And it has made me consider +writing more mixins and using Python's multiple inheritance more. This +is not completely new to me, but I finally tested it a few days ago +and what I thought I knew seems to have been confirmed. + +Given some classes: + +#+NAME: setup +#+BEGIN_SRC python :exports code :results output :session + class Foo(object): + def frob(self): + print('foo') + + + class Bar(Foo): + def frob(self): + super(Bar, self).frob() + print('bar') + + + class BazMixin(object): + def frob(self): + super(BazMixin, self).frob() + print('baz') + + + class Unmixed(Bar, BazMixin): + def frob(self): + super(Unmixed, self).frob() + print('unmixed') + + + class Mixed(BazMixin, Bar): + def frob(self): + super(Mixed, self).frob() + print('mixed') +#+END_SRC + +#+RESULTS: setup + +We can see the progression of inheritance. You will see here that +=BazMixin= is skipped: + +#+NAME: unmixed +#+BEGIN_SRC python :exports both :results output :session + unmixed = Unmixed() + unmixed.frob() +#+END_SRC + +#+RESULTS: unmixed +: +: foo +: bar +: unmixed + +And here that it is not: + +#+NAME: mixed +#+BEGIN_SRC python :exports both :results output :session + mixed = Mixed() + mixed.frob() +#+END_SRC + +#+RESULTS: mixed +: +: foo +: bar +: baz +: mixed diff --git a/articles/rlwrapping_sbcl.org b/articles/rlwrapping_sbcl.org new file mode 100644 index 0000000..cc8d94d --- /dev/null +++ b/articles/rlwrapping_sbcl.org @@ -0,0 +1,18 @@ +#+TITLE: rlwrapping sbcl + +[[http://sbcl.org][SBCL]] is an excellent lisp implementation. The only thing that's not so +nice about it is overly simple command-line interface. The absence of +~~, ~C-a~, ~M-b~, etc. can be annoying, even though I only occasionally +use SBCL directly. + +I have 3 solutions to this problem now: + +- Use [[http://common-lisp.net/project/slime/][SLIME]], which is what I do most of the time, but sometimes this + isn't practical. + +- Use [[http://common-lisp.net/project/linedit/][Linedit]]. I tried this, and it was cool. But somehow I broke it + and now I can't get it to work. + +- Use [[http://utopia.knoware.nl/~hlub/uck/rlwrap/#rlwrap][rlwrap]]. This requires you to either always invoke SBCL as + =rlwrap sbcl= or create an alias for it. This works very well too, + is very simple and doesn't noticeably increase start-up time. diff --git a/articles/some_quick_git_diff_tips.org b/articles/some_quick_git_diff_tips.org new file mode 100644 index 0000000..e9d3f39 --- /dev/null +++ b/articles/some_quick_git_diff_tips.org @@ -0,0 +1,56 @@ +#+TITLE: Some quick git diff tips + +A couple of quick tips. As you possibly know you can specify some +options to be used for diffs (and other things) per file type. The +one I'm interested in is the function name. + +* For org-mode + + The primary way of identifying which part of an org-mode document + a change occurs in seems to me to be the heading. So, in your + ~$HOME/.gitconfig~ put: + + #+BEGIN_SRC conf + [diff "org"] + xfuncname = "^\\*+.*" + #+END_SRC + + Which should show any lines starting with one or more ~*~ + characters. And then in ~$XDG_CONFIG_HOME/git/attributes~ or + ~$HOME/.config/git/attributes~ put: + + #+BEGIN_EXAMPLE + ,*.org diff=org + #+END_EXAMPLE + +* For lisp and lisp-like langauges + + For anything that resembles lisp (so Common Lisp, Emacs Lisp, Hy, + scheme, etc.) I would think that the easiest thing to do is just + see the closes top-level form. So, in your ~$HOME/.gitconfig~ put: + + #+BEGIN_SRC conf + [diff "lisp"] + xfuncname = "^\\([^ ]+ [^ ]+" + #+END_SRC + + Which should show the opening parenthesis and the first two words. + For example: + + #+BEGIN_EXAMPLE + (defun some-function-name + (defclass my-awesome-class + (define-route this-strange-route + #+END_EXAMPLE + + And then put in your ~$XDG_CONFIG_HOME/git/attributes~ or + ~$HOME/.config/git/attributes~: + + #+BEGIN_EXAMPLE + ,*.lisp diff=lisp + ,*.el diff=lisp + ,*.hy diff=lisp + ,*.scm diff=lisp + #+END_EXAMPLE + + And possibly any other lisp-like language files you can think of. diff --git a/blog.org b/blog.org new file mode 100644 index 0000000..9709925 --- /dev/null +++ b/blog.org @@ -0,0 +1,45 @@ +#+TITLE: +#+OPTIONS: toc:nil +#+STARTUP: showall +#+HTML_LINK_UP: ./ +#+RSS_EXTENSION: rss + +# * Python mixins :python:coding: +# :PROPERTIES: +# :PUBDATE: <2013-11-10 Sun 15:35> +# :RSS_PERMALINK: articles/python-mixins.html +# :END: +# A little explanation of one of the things that I think make Mixins +# in Python an interesting idea. + +# [[file:articles/python-mixins.org][Read]] + +* Mounting music dir before MPD :systemd:mpd:config: + :PROPERTIES: + :RSS_PERMALINK: articles/mounting_music_dir_before_mpd.html + :PUBDATE: <2013-11-24 Sun 14:03> + :END: + I use an NFS drive to store my music files, which I don't mount by + default (to keep startup fast). It was a pain to have to mount the + drive manually each time before starting MPD. [[file:articles/mounting_music_dir_before_mpd.org][Read]] + +* rlwrapping sbcl :sbcl:lisp:utility: + :PROPERTIES: + :RSS_PERMALINK: articles/rlwrapping_sbcl.html + :PUBDATE: <2013-10-06 13:02> + :END: + A useful addition to SBCL. [[file:articles/rlwrapping_sbcl.org][Read]] + +* C-d to close eshell :eshell:emacs:elisp:config: + :PROPERTIES: + :PUBDATE: <2013-08-17 2:25> + :RSS_PERMALINK: articles/c-d_to_close_eshell.html + :END: + A little trick to improve your eshell experience. [[file:articles/c-d_to_close_eshell.org][Read]] + +* Some quick git diff tips :org:lisp:hy:elisp:scheme:config: + :PROPERTIES: + :RSS_PERMALINK: articles/some_quick_git_diff_tips.html + :PUBDATE: <2013-08-11 0:54> + :END: + Making git see more diff. [[file:articles/some_quick_git_diff_tips.org][Read]] diff --git a/index.org b/index.org index 23eb426..a8f9435 100644 --- a/index.org +++ b/index.org @@ -3,18 +3,29 @@ #+STARTUP: showall #+OPTIONS: toc:nil H:1 -* My coding projects +* Blog + + Some thoughts I may have had, and was foolish enough to write down. + + #+BEGIN_SRC emacs-lisp :exports results :results value raw + (apply + #'concat + (with-current-buffer (find-file-noselect "blog.org") + (org-map-entries + (lambda () + (format "* [[file:%s][%s]] %s\n" + (org-entry-get (point) "RSS_PERMALINK") + (nth 4 (org-heading-components)) + (org-entry-get (point) "PUBDATE")))))) + #+END_SRC + +* Projects These are the projects I keep myself busy with in my free time. Some may be old, all might be badly written and one or two might be useful. They are not sorted in order of importance, popularity or size. -** [[file:projects/baps1.org][baps1]] :C: - - A simple PS1 formatting utility. Doesn't do a lot yet, but does it a - hell of a lot faster than the PHP script it replaced. (I hope) - ** [[file:projects/cdispass.org][cdispass]] :Conkeror:JavaScript: A [[http://conkeror.org][Conkeror]] interface for [[http://dispass.babab.nl][DisPass]]. Input your passphrases directly @@ -56,6 +67,11 @@ one, he doesn't actually look anything like this theme, for example: He doesn't have so much text all over him. +** [[file:projects/baps1.org][baps1]] :C: + + A simple PS1 formatting utility. Doesn't do a lot yet, but does it a + hell of a lot faster than the PHP script it replaced. (I hope) + ** more I have [[http://code.ryuslash.org][other projects]] around here too. Not sure if you would be @@ -92,5 +108,3 @@ * Other forms of communication - Read a little [[file:about.org][about]] me. - - - Read my [[http://blog.ryuslash.org/][blog]], it has boring things.. diff --git a/org.css b/org.css index 4094807..5495e8c 100644 --- a/org.css +++ b/org.css @@ -8,14 +8,41 @@ a:hover { body { border: 0; - font-family: sans-serif; + font-family: "PT Sans", sans-serif; margin: 0; padding: 0; line-height: 160%; + font-size: 15px; +} + +h1 { + font-size: 25px; +} + +h2 { + font-size: 23px; +} + +h3 { + font-size: 21px; +} + +h4 { + font-size: 19px; +} + +h5 { + font-size: 17px; +} + +h6 { + font-size: 15px; } pre { line-height: 100%; + font-family: "PT Mono", monospace; + margin: 1.2em -8pt; } .tag { @@ -29,6 +56,10 @@ pre { padding: 2px 4px; } +.timestamp { + float: right; +} + #content, #org-div-home-and-up, #postamble { diff --git a/project.el b/project.el index 787815b..f712d6d 100644 --- a/project.el +++ b/project.el @@ -1,4 +1,5 @@ (require 'org-publish) +(require 'ox-rss) ;; (require 'ox-html) ;; (defun org-html-template (contents info) @@ -132,6 +133,9 @@ (setq org-html-head-include-scripts nil org-html-validation-link nil org-publish-use-timestamps-flag nil + org-html-htmlize-output-type 'css + org-rss-extension "rss" + org-confirm-babel-evaluate nil org-publish-project-alist '(("oni-files" :base-directory "./" @@ -148,5 +152,12 @@ :section-numbers nil :table-of-contents 1 :html-doctype "" - :html-head "" - :html-link-home "http://ryuslash.org"))) + :html-head "" + :html-link-home "https://ryuslash.org") + ("rss" + :base-directory "./" + :publishing-directory "_publish/" + :base-extension "" + :publishing-function org-rss-publish-to-rss + :include ("blog.org") + :html-link-home "https://ryuslash.org")))