Table of contents

Render current HTML buffer with EWW

From time to time I end up with raw HTML content in an emacs buffer and want to know how it looks or just want to read it properly. Until now either I opened firefox to read that file or I opened it with eww-open-file. The problem is, that sometimes there is no file, the HTML buffer is just the output of some generator or something. In such cases I needed to save the buffer as a file and then re-open it with EWW. Very annoying.

With this simple function the nightmare is over. I just use the EWW internal render function to do the job. That way I can view any HTML in emacs without even saving it to disk.

(require 'eww)

(defun eww-render-current-buffer () “Render HTML in the current buffer with EWW” (interactive) (beginning-of-buffer) (eww-display-html ‘utf8 (buffer-name)))

(global-set-key (kbd "<C-c C-e C-w C-w>") ’eww-render-current-buffer)

Now when I'm inside a HTML buffer, I can just render it and take a look with EWW. Very handy!

↷ 08.06.2017 🠶 #emacs

Finlay

Finlay is seit Dezember 2016 bei uns. Er kommt aus einer Tötungsstation im Ausland. Wir trainieren viel, Schmusen viel und sind happy mit ihm. Hier ein paar erste Bilder:

2017-06-12 - Ein Küschen für die (grosse!) Dame:

2017-06-12 - So gut muss man es haben:

2017-05-14 - Training, Training, Training:

2017-05-14 - Cheeees!:

2017-05-14 - Hübscher Bub oder?:

2017-05-14 - Geschmückt, aber Müüüüüde:

↷ 14.05.2017 🠶 #hund

Cheap RSA Paper Token Holder

Materail needed: Paper (I suggest  photo paper which is thicker), scissors. Build instructions: trim the paper and fold it appropreately. Done. Now you can plase the token on your desk an read the numbers without taking your hands off the keyboard. Relief!

2017-05-13 - The token holder:

↷ 13.05.2017 🠶 #networking

Emacs: Mark, Copy and Yank Things

In a previous post I described how I copy various things at point in emacs to make my daily live easier. Meanwhile the code grew larger and larger and in the end went too large to maintain it in my emacs config.

So, I descided to put it into its own module: mark-copy-yank-things-mode. As always you can find the mode on github.

There are a couple of new features now: I created a copy-comment-block function which is able to copy comment blocks even if they are on the right side of some code. Here's a demo gif:

Also, there is now support for email addresses, ip addresses and urls. The mode provides prefix keys mappings, so, it's very easy to change the key mapping for the various functions just by modifying the prefix key.

Here's a lis of the current default key bindings provided by the mode:

COPY commands (keymap: mcyt-copy-map):

C-c c w      mcyt-copy-word 
C-c c q      mcyt-copy-quote 
C-c c k      mcyt-copy-parens 
C-c c l      mcyt-copy-line 
C-c c p      mcyt-copy-paragraph 
C-c c f      mcyt-copy-defun 
C-c c u      mcyt-copy-url 
C-c c e      mcyt-copy-email 
C-c c c      mcyt-copy-comment-block 
C-c c a      mcyt-copy-buffer 
C-c c i      mcyt-copy-ip 
C-c c s      mcyt-copy-sexp

COPY & YANK commands (keymap: mcyt-yank-map):

C-c c y y    mcyt-copy-and-yank-line
C-c c y l    mcyt-copy-and-yank-line
C-c c y p    mcyt-copy-and-yank-paragraph
C-c c y f    mcyt-copy-and-yank-defun
C-c c y a    mcyt-copy-and-yank-buffer
C-c c y w    mcyt-copy-and-yank-word
C-c c y i    mcyt-copy-and-yank-ip
C-c c y c    mcyt-copy-and-yank-comment

MARK commands (keymap: mcyt-mark-map):

C-c c a a    mcyt-mark-buffer 
C-c c a w    mcyt-mark-word 
C-c c a f    mcyt-mark-defun 
C-c c a p    mcyt-mark-paragraph 
C-c c a l    mcyt-mark-line 
C-c c a u    mcyt-mark-url 
C-c c a e    mcyt-mark-email 
C-c c a s    mcyt-mark-sexp 
C-c c a c    mcyt-mark-comment-block 
C-c c a i    mcyt-mark-ip 

Update 2017-03-28:

From time to time I stumble upon a very annoying emacs behavior: I copy some text and want to insert it into multiple positions somewhere else. However, I need to delete something on those positions before yanking. Now, this deleted stuff will be added to the kill-ring and appears first, when I execute yank the next time. So, I need to cycle through the kill-ring with M-y to reach the text I really want to yank. And everytime this text moves further away. So, this is what I type in those situations:

C-<backspace>
C-y
[..]
C-<backspace>
C-y
M-y
[..]
C-<backspace>
C-y
M-y
M-y
[..]
C-<backspace>
C-y
M-y
M-y
M-y
[..]
C-<backspace>
C-y
M-y
M-y
M-y
M-y
[..]

You see, this is very annoying. Here's how I fixed this: I just added a defadvice to my copying code of the above module, which puts the copied text into a emacs text register. And I created a new key binding to access this text register: C-v. I do not use this in emacs for cursor movement (its original binding) anyway and its the default PASTE key binding on some OS'es and applications - so I'm already somewhat used to it. Now I can always yank the last copied text and it doesn't matter how many items I added to the kill-ring since copying.

Here's the code:

(advice-add
  'mcyt--copy-thing :after
     '(lambda (&rest args)
        (with-temp-buffer
          (yank)
          (copy-to-register 'c (point-min) (point-max)))))

(defun my-insert-c-register () (interactive) (insert-register ‘c))

(global-set-key (kbd “C-v”) ‘my-insert-c-register)

↷ 23.03.2017 🠶 #emacs

Portable Emacs Eshell Aliases

I maintain one emacs config file (.emacs) for all environments and systems whereever I use emacs. From time to time I use eShell but aliases were differing from system to system. The reason was, that they were stored in a separate file (~/.emacs.d/eshell/aliases) which I do not re-distribute.

So, my solution was to maintain eshell aliases inside my .emacs file. Here are my current alias definitions:

;; actual aliases
(+alias 'l      '(ls -laF))
(+alias 'll     '(ls -l))
(+alias 'la     '(ls -a))
(+alias 'lt     '(ls -ltr $*))
(+alias '..     '(cd ..))
(+alias '...    '(cd ../..))
(+alias '....   '(cd ../../..))
(+alias '.....  '(cd ../../../..))
(+alias 'md     '(mkdir -p))
(+alias 'emacs  '(find-file $1))
(+alias 'less   '(find-file-read-only $1))

As you can see, I use a pretty handy function +alias to create them and I use symbols, not strings which looks cleaner. For this to work, I use the following function:

(setq eshell-command-aliases-list ())

(defun +alias (al cmd) “handy wrapper function to convert alias symbols to alias
strings to avoid writing 4 quotes per alias. AL is a single-word
symbol naming the alias, CMD is a list symbol describing the
command."
(add-to-list ’eshell-command-aliases-list (list (symbol-name al) (mapconcat ‘symbol-name cmd ” “))))

So, first the aliases list will be cleared, just in case there's some aliases file left in the filesystem (which I ignore from now on). The function +alias then converts the given symbols to strings and adds them to the alias list.

I could of course use strings directly but that's too much quotes to type and looks confusing. Just for completeness, here's how the aliases list looks like after the above conversion:

(("less" "find-file-read-only-other-window $1")
 ("emacs" "find-file-other-window $1")
 ("md" "mkdir -p")
 ("....." "cd ../../../..")
 ("...." "cd ../../..")
 ("..." "cd ../..")
 (".." "cd ..")
 ("lt" "ls -ltr $*")
 ("la" "ls -a")
 ("ll" "ls -l")
 ("l" "ls -laF"))

↷ 13.03.2017 🠶 #emacs