Diary SiteMap RecentChanges About Contact Calendar


Matching Pages:


Emacs Feed The pages where I write about Emacs. It doesn’t happen very often. I think you’re probably best off following Planet Emacsen.

2014-04-07 Homebrew Problems

I’ve been using Homebrew on our Mac for a while now. I like it very much. I’ve recently run into an issue, though. Sending emails from Emacs stopped working. I was getting was this:

Opening STARTTLS connection to `fencepost.gnu.org:25'...failed
network-stream-get-response: Wrong type argument: processp, nil

The important setting to remember to learn more is this:

(setq smtpmail-debug-info t)

Resent the mail and switch to a buffer called *trace of SMTP session to fencepost.gnu.org*.


220 fencepost.gnu.org ESMTP Exim 4.71 Mon, 07 Apr 2014 01:00:52 -0400
250-fencepost.gnu.org Hello 178-83-163-103.dynamic.hispeed.ch []
250-SIZE 52428800
250 HELP

Process smtpmail deleted
dyld: Library not loaded: /usr/local/lib/libnettle.4.7.dylib
  Referenced from: /usr/local/bin/gnutls-cli
  Reason: image not found

Process smtpmail trace/BPT trap: 5

Oops, it seems that I uninstalled something that gnutls required!

Time to check things:

alex@Megabombus:/usr/local/bin (master)$ brew update
alex@Megabombus:/usr/local/bin (master)$ brew upgrade nettle
Error: nettle-2.7.1 already installed
alex@Megabombus:/usr/local/bin (master)$ brew upgrade gnutls
Error: gnutls- already installed
alex@Megabombus:/usr/local/bin (master)$ ls /usr/local/lib/libnettle.*
/usr/local/lib/libnettle.4.5.dylib /usr/local/lib/libnettle.a
/usr/local/lib/libnettle.4.dylib   /usr/local/lib/libnettle.dylib
alex@Megabombus:/usr/local/bin (master)$ brew reinstall gnutls
==> Reinstalling gnutls
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/gnutls-3.2.
Already downloaded: /Library/Caches/Homebrew/gnutls-
==> Pouring gnutls-
🍺  /usr/local/Cellar/gnutls/ 931 files, 8,4M
alex@Megabombus:/usr/local/bin (master)$ brew reinstall nettle
==> Reinstalling nettle
Warning: nettle-2.7.1 already installed, it's just not linked
alex@Megabombus:/usr/local/bin (master)$ brew link  nettle
Linking /usr/local/Cellar/nettle/2.7.1... 16 symlinks created
alex@Megabombus:/usr/local/bin (master)$ gnutls-cli --version
gnutls-cli 3.2.12
Copyright (C) 2000-2014 Free Software Foundation, and others, all rights reserved.
This is free software. It is licensed for use, modification and
redistribution under the terms of the GNU General Public License,
version 3 or later <http://gnu.org/licenses/gpl.html>

Please send bug reports to:  <bugs@gnutls.org>

That seems to have fixed it!

I wonder how this happened in the first place.


Add Comment

2014-02-14 Finding Duplicate Files

I have a ton of files I downloaded to my tablet and I have a ton of files on my external harddisk. How can I ever clean it all up? With Emacs, I have dired, but no easy way to figure out which files have changed – specially if the files are not all in the same directory structure. Based on EmacsWiki:JoeBloggsdired-dups.el I wrote a new version that did what I wanted it to do.

Find dired-duplicates.el on GitHub.

Now that I think about it, I guess my code does the exact opposite: it find differences, not duplicates. I should change those names…

(As it turns out, there are still bugs in the code. Ouch.)

Tags: RSS

Add Comment

2013-12-02 Emacs Defaults

I saw Andrew Hyatt post on Google+:

From the emacs-devel list comes a query for builtin packages that would be useful to enable by default.
They are interested in getting feedback from the community. If you have a builtin package you think should be enabled by default, add a comment, and we circulate this back to the emacs-devel list.

Check it out via Gmane, and now a survey on Emacs Wiki.

I skimmed my ~/.emacs and looked at all the little settings I think would make better defaults… For the complete file, see my current config file for Emacs on Windows.

(show-paren-mode 1)
(winner-mode 1)
(column-number-mode 1)
(savehist-mode 1)
(iswitchb-mode 1)
(global-set-key (kbd "C-x C-b") 'bs-show)
(require 'dired-x)
(setq dired-recursive-deletes 'top
      dired-recursive-copies 'top
      dired-dwim-target t)
(setq sentence-end-double-space nil)
(dolist (hook '(emacs-lisp-mode-hook
  (add-hook hook (lambda ()
           (eldoc-mode 1)
           (set (make-local-variable 'sentence-end-double-space) t))))
(setq eshell-save-history-on-exit t)
(setq cperl-hairy t
      cperl-electric-parens 'null)
(add-hook 'cperl-mode-hook
      (lambda ()
        (local-set-key (kbd "C-h f") 'cperl-perldoc)))
(add-hook 'rcirc-mode-hook
      (lambda ()
        (rcirc-track-minor-mode 1)))

(defun describe-hash (variable &optional buffer)
  "Display the full documentation of VARIABLE (a symbol).
    Returns the documentation as a string, also.
    If VARIABLE has a buffer-local value in BUFFER (default to the current buffer),
    it is displayed along with the global value."
   (let ((v (variable-at-point))
     (enable-recursive-minibuffers t)
     (setq val (completing-read
        (if (and (symbolp v)
             (hash-table-p (symbol-value v)))
             "Describe hash-map (default %s): " v)
          "Describe hash-map: ")
        (lambda (atom) (and (boundp atom)
                    (hash-table-p (symbol-value atom))))
        t nil nil
        (if (hash-table-p v) (symbol-name v))))
     (list (if (equal val "")
           v (intern val)))))
  (with-output-to-temp-buffer (help-buffer)
    (maphash (lambda (key value)
           (pp key)
           (princ " => ")
           (pp value)
         (symbol-value variable))))

(define-key isearch-mode-map (kbd "C-h") 'isearch-highlight-phrase)

(put 'narrow-to-region 'disabled nil)
(put 'not-modified 'disabled t)
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)

Tags: RSS

Add Comment

2013-10-22 Random Names on IRC

Sometimes I wonder whether nicks on IRC give too much away. Sex, cultural background, … So here’s an experiment. Do you treat the people the same if you can’t see their nick names?

The following setup uses colored nicks and random names for Emacs:rcirc.

rcirc: Random Names

Tags: RSS

Add Comment

2013-07-26 Extracting Starred URLs from Google Reader Takeout Data

Google Reader was shut down. Luckily Google Takeout allowed you to download all of your data before the shut it down. I did that. I wanted to extract all the URLs to the articles I starred in order to post them on this blog… maybe.

Here’s how I did it. First, take a look at the file starred.json.

    (setq starred-items (with-current-buffer "starred.json (Google Reader-takeout.zip)"
			  (goto-char (point-min))
    (mapcar (lambda (item) (car item)) starred-items)
    ⇒ (items direction updated author title id)

I’m interested in items, which happens to be an array. Let’s see what each item contains.

    (mapcar (lambda (item) (car item))
            (aref (cdr (assoc-string "items" starred-items)) 0))
    ⇒ (origin annotations comments author content replies alternate updated published title categories id timestampUsec crawlTimeMsec)

As it happens, the URL I’m interested in is part of alternate. Let’s make sure there’s always exactly one entry:

    (mapc (lambda (item)
	    (when (not (= 1 (length (cdr (assoc-string "alternate" item)))))
	      (error "%S" item)))
	  (cdr (assoc-string "items" starred-items)))

Phew! Let’s produce a first list of URLs and the respective titles:

    (mapc (lambda (item)
	    (let ((href (cdr (assoc-string "href"
					   (aref (cdr (assoc-string "alternate" item)) 0))))
		  (title (cdr (assoc-string "title" item))))
	      (insert (format "* [%s %s]\n" href title))))
	  (cdr (assoc-string "items" starred-items)))

I hate feedproxy URLs and so I absolutely wanted to get rid of all the URLs starting with http://feedproxy.google.com/. This required a bit more code since neither url-retrieve-synchronously nor url-retrieve do exactly what I want.

    (defun redirection-target (url)
	(let ((url-request-method "HEAD")
	      (retrieval-done nil)
	      (spinner "-\|/")
	      (n 0))
	  (url-retrieve url
			(lambda (status &rest ignore)
			  (setq retrieval-done t
				url (plist-get status :redirect)
				url (replace-regexp-in-string "blogspot\\.ch" "blogspot.com" url)
				url (replace-regexp-in-string "\\?utm.*" "" url))))
	  (while (not retrieval-done)
	    (sit-for 1)
	    (message "Waiting... %c" (aref spinner (setq n (mod (1+ n) (length spinner))))))

Now I can run the following search an replace operation in the buffer where I generated my list:

    (while (re-search-forward "http://feedproxy\\.google\\.com/\\S-+" nil t)
      (replace-match (redirection-target (match-string 0))))

Phew, thank you, Emacs!

Tags: RSS

Add Comment

2013-05-08 Distributing XP With Emacs

This topic ties together two topics that probably don’t see too much overlap.

  1. I play role-playing games of the D&D old school variety.
  2. I use Emacs to help me do simple stuff on a daily basis.

The problem: the party of characters my players run is huge. Even if there are usually only around ten characters that are part of a single session, there are more than thirty primary and secondary characters on the status page. Given the wiki table for the status page, how can I quickly add up the correct XP and gold values? Any XP gained is shared equally amongst the characters that took part in the session but any gold gained is distributed according to each characters share. Primary characters get a full share, secondary characters get a third of a share.

I used Emacs widget mode to create a page like this:

XP total:   805          
Gold total: 7191         
[X] Schalk
[ ] Uluf
[ ] Witschik
[X] Schachtmann
[ ] Sirius
[X] Logard
[X] Arnd
[X] Tinaya
[ ] Pyrula
[ ] Pijo
[ ] Garo
[X] Zeta
[ ] Pipo
[X] Fusstritt
[ ] Thor
[ ] Jack
[ ] Gloria
[ ] Hermann
[ ] Urs
[ ] Alpha
[ ] Beta
[ ] Gamma
[ ] Boden
[ ] Basel
[ ] Bern
[X] Nuschka
[ ] Moranor
[ ] Axirios Hectaxius


And here’s the code to do it:

(defconst fünf-winde-regexp "^\\(|\\[\\[\\(.*?\\)\\]\\][ \t]*|[ \t]*\\(1\\|1/3\\)[ \t]*\\)|\\([ \t]*[0-9]+[ \t]*\\)|\\([ \t]*[0-9]+[ \t]*\\)"
  "Regular expression to parse the Status page.
\(let ((str (match-string 1))
      (name (match-string 2))
      (share (match-string 3))
      (xp (match-string 4))
      (gold (match-string 5)))

(defvar fünf-winde-buf nil
  "Source buffer.")

(defvar fünf-winde-xp nil
  "XP share.")

(defvar fünf-winde-gold nil
  "Gold share.")

(defvar fünf-winde-party nil
  "Charakters in the party.")

(defun fünf-winde-xp-and-gold ()
  "Hand out Gold and XP."
  (let ((buf (current-buffer))
      (goto-char (point-min))
      (while (re-search-forward fünf-winde-regexp nil t)
	(setq names (cons (match-string 2) names))))
    (switch-to-buffer "*Fünf Winde*")
    (set (make-local-variable 'fünf-winde-buf) buf)
    (make-local-variable 'fünf-winde-xp)
    (make-local-variable 'fünf-winde-gold)
    (make-local-variable 'fünf-winde-party)
    (let ((inhibit-read-only t))
    (setq fünf-winde-xp
	  (widget-create 'integer
			 :size 13
			 :format "XP total:   %v\n"
    (setq fünf-winde-gold
	  (widget-create 'integer
			 :size 13
			 :format "Gold total: %v\n"
    (setq fünf-winde-party
	  (apply 'widget-create 'checklist
		 (mapcar (lambda (name)
			   `(item ,name))
			 (nreverse names))))
    (widget-insert "\n")
    (widget-create 'push-button
		   :notify (lambda (&rest ignore)
			      (widget-value fünf-winde-xp)
			      (widget-value fünf-winde-gold)
			      (widget-value fünf-winde-party)))
    (widget-insert "\n")
    (use-local-map widget-keymap)
    (local-set-key (kbd "q") 'bury-buffer)
    (local-set-key (kbd "SPC") 'widget-button-press)
    (local-set-key (kbd "<left>") 'widget-backward)
    (local-set-key (kbd "<up>") 'widget-backward)
    (local-set-key (kbd "<right>") 'widget-forward)
    (local-set-key (kbd "<down>") 'widget-forward)
    (goto-char (point-min))
    (widget-forward 1)))

(defun fünf-winde-process (buf total-xp total-gold party)
  (message "(fünf-winde-process (get-buffer \"%s\") %d %d '%S)"
	   buf total-xp total-gold party)
  (switch-to-buffer buf)
    (let ((xp-shares 0)
	  (xp-share nil)
	  (gold-shares 0)
	  (gold-share nil))
      (goto-char (point-min))
      (while (re-search-forward fünf-winde-regexp nil t)
	(let ((name (match-string 2))
	      (share (match-string 3)))
	  (when (member name party)
	    (setq gold-shares (+ gold-shares
				 (cond ((string= share "1/2") 0.5)
				       ((string= share "1/3") (/ 1.0 3))
				       (t (string-to-number share))))
		  xp-shares (1+ xp-shares)))))
      (setq gold-share (/ total-gold gold-shares)
	    xp-share (/ total-xp xp-shares))
      (goto-char (point-min))
      (while (re-search-forward fünf-winde-regexp nil t)
	(let ((str (match-string 1))
	      (name (match-string 2))
	      (share (match-string 3))
	      (xp (match-string 4))
	      (gold (match-string 5)))
	  (when (member name party)
	    (setq gold (format (concat "%9d")
			       (+  (string-to-number gold)
				   (* gold-share (cond ((string= share "1/2") 0.5)
						       ((string= share "1/3") (/ 1.0 3))
						       (t (string-to-number share))))))
		  xp (format (concat "%9d")
			     (+  (string-to-number xp)
	    (replace-match (concat str
				   "|" xp
				   "|" gold))))))))

I’m not sure I’m spending my time wisely, but there you go. I used to have a simpler piece of code that helped me distribute XP and gold separately. The drawback was that it would ask me for every person in the table “was this character in the party? (y/n)” and that’s a lot of yes and no replies if you go through the list twice.

It’s also a stark reminder that simpler old rules doesn’t automatically mean less work for the referee. With D&D 3.5, I had a spreadsheet to compute the XP gained based on challenge rating and character level. It wasn’t something to do quickly without a book in front of me. Now the complexity of the task has been reduced, but the number of characters has exploded to compensate!


Add Comment

2013-04-26 Emacs Wiki Redesign

I finally installed the new theme for Emacs Wiki. Feel free to leave comments on the Talk page. Bootstrap allows me to make all the changes at run-time, ie. add a few scripts including a script that changes the wiki’s HTML (emacs-bootstrap.js) and a new CSS file (bootstrap.css).

Since no changes to the script are necessary I can continue to provide the old theme for those that don’t feel like switching.

Tags: RSS

Comments on 2013-04-26 Emacs Wiki Redesign

Yay for bootstrap! It really makes the life easier if you want your web application to look consistently.

Radomir Dopieralski 2013-04-26 15:22 UTC

Add Comment

2013-01-23 Security of Code Downloaded from Online Sources

In the anonymous rant The Wikemacs Experiment: 300 Days Later, the author claims “The biggest problem is that it is insecure. […] Anyone can edit any of the pages that contain Elisp code.” The same sentiment was expressed by Alex Bennée in a comment on Google+: “What is really needed is a way to be sure that the source for the emacs extension your updating hasn’t been subverted by someone else with ill intent.”

I said:

Experiences and ideas of “what is really necessary” vary. As for myself, I’ve installed code from all over the Internet without reviewing the source. Installing it from a gist or git repo is hardly a different experience. If you want to figure out whether a source is trustworthy, you do the usual things: do people link to the code, how long has it been around, what about recent checkins, that sort of thing. Or you get into the crypto business of signing releases.

You could of course say that every day that passes without a problem increases our false sense of security… I have no answer to that. All I can say is that if security is your problem, using gists and github is not the solution (as you say yourself). The source of the insecurity is our habits, our culture of downloading and installing anything and everything. I’m not sure how you’ll ever make sure “that the source for the emacs extension your updating hasn’t been subverted by someone else with ill intent.” That seems pretty impossible to me unless you limit yourself to the core Emacs distribution (and even that’s not a guarantee).

People on the #emacs channel keep asking “is there way to do X” and thus my impression is that finding stuff is a more pressing problem. I feel that encouraging people to create a page on the wiki saying “here is code to help you do something” is the solution to that problem.

But then again, I guess we all differ in what we consider to be the most pressing problem.

Alex Bennée the correctly points out that using “a user locked solution like a gist or git repo you can at least be assured what you’re installing has come through one person who you’ve trusted to a degree before.” I guess that’s true. We’ll see whether people start switching over to using gists instead of editing wiki pages. I said in an earlier comment:

I added gist support […] because it was easy to do, not because it will encourage existing authors to move their elisp code on wiki pages to github. If at all, it might encourage future elisp authors to transclude a gist… But then again, there’s nothing preventing them from linking to a gist right now. Perhaps it’s also a generational thing. People that have been living without github and gists don’t feel a particular need to start using it.

Interesting times. :)


Comments on 2013-01-23 Security of Code Downloaded from Online Sources

Hi Alex,

first of all - thank you very much for Oddmuse! I’m using it for both my personal site and Department's site. It has some rough edges, but overall I find it a very nice tool, and I did recommend it to a few people.

Now to the point: I was just wondering whether it might be a good idea to use stackoverflow with [emacs] tag (which you mentioned in your earlier post), or maybe even start something like emacs.stackexchange.com? I’m not sure whether it could solve any problems you mentioned, but (at least for the more paranoia-oriented people) it might feel a bit more secure, with all the comments, up- and downvotes etc. I don’t know. (Personally, I didn’t use any actual code from Emacswiki, but I guess it would not be a huge problem for me.)

mbork 2013-01-23 20:55 UTC

Nothing has really changed. Previously, Lisp code was shared between a few Emacs hackers and the intention was to work on improving it and get it integrated into Emacs. The GNU Project was the trusted authority. They distributed the useful contributions. Obviously, that hasn’t scaled well. I think it’s perfectly reasonable for Emacs newbies to distrust code they can’t read that was written by hackers they don’t know.

AaronHawley 2013-01-23 21:56 UTC

Thank you for the kind words, Marcin. I think a lot of people are already using Stackoverflow for Emacs questions. I find the site incredibly useful when I’m at work (except my work is hardly ever related to Emacs, unfortunately).

I also agree with Aaron. Good point regarding the GNU Project being the trusted authority.

AlexSchroeder 2013-01-23 22:39 UTC

Thomas Koch
I’ve collected examples of manipulated code or binaries: http://www.koch.ro/blog/index.php?/archives/153-On-distributing-binaries.html

I don’t think that it’s too hard to get a gpg key, go to a signing party on your next software conference and sign all your releases. It’s rather dumb easy. And you can use signed git tags on github or any other git hosting platform to provide a very strong confidence for your user that they can trace you back in case you provided bad code.

Thomas Koch 2013-01-24 12:57 UTC

True, it is not “too hard” for many people. But when I write a little throw-away piece of code like EmacsWiki:1000 Words it’s a bit much to ask. I’ve never been to a key signing party. I never go to software conferences. I post it on the wiki. And when I write another little piece of code, I do it again. That’s why my code ends up on the wiki and not on github. I keep hoping people will volunteer to maintain code I wrote and either add it to Emacs itself or maintain it in decent repositories. I just don’t see myself doing it. I like the division of labor between programming and packaging.

AlexSchroeder 2013-01-25 10:24 UTC

Thomas Koch
It might be a bit too much to sign a little script of 10 lines that I can quickly review. I was rather referring to big software projects. However once you’ve got a gpg key you can sign a small code snippet just as easily as you can sign an email.

Thomas Koch 2013-01-26 10:11 UTC

I think now the discussion turns to the question of where to draw the line. There’s exactly one large project that is exclusively hosted on Emacs Wiki, I think: EmacsWiki:Icicles. Others, such as EmacsWiki:Anything moved to github. Other, like EmacsWiki:Gnus or EmacsWiki:BBDB were never hosted on Emacs Wiki to begin with. Then there are the large collection of inofficial extensions like the ones listed on EmacsWiki:rcirc. Do they count as a single project or is each file a separate one? From my point of view, each one is a separate project. I just use two of them myself. As such, they are not really “a little script of 10 lines” but they don’t feel like big software projects, either.

I think I’m with Aaron. Emacs Wiki mostly hosts code on the wiki that one could view as “incubator” stuff. Things that haven’t made it into their own repositories or that haven’t made it into Emacs itself. Thus, asking for version control and signed releases is—in the context of code hosted on Emacs Wiki—asking for the right thing at the wrong time. It’s premature for those small single file projects that are hanging in Limbo somewhere between ten lines and inclusion into Emacs or indendence as their separate projects.

AlexSchroeder 2013-01-26 11:46 UTC

Using El-Get you can easily add a checksum in your setup so that you only automatically get code from EmacsWiki with that checksum. So if you get to a new machine or re-install your Emacs setup from scratch, and the newly downloaded EmacsWiki code does not match your checksum, El-Get will refuse to load it for you. You can get the checksum interactively using M-x el-get-checksum command.

dim 2013-01-27 21:13 UTC

Excellent feature!

AlexSchroeder 2013-01-28 07:23 UTC

Add Comment

2013-01-22 Gists on Emacs Wiki

I just read a rant about Emacs Wiki and it’s alternative: The Wikemacs Experiment: 300 Days Later. Check out How Emacs Wiki Works for some context from my point of view. Anyway, the anonymous author says: “Maybe someone could work with Alex to add gist-style code snippets to Oddmuse, and make it so that code can be cited inline on Wiki pages, so that anyone visiting the page is automatically looking at the most up to date version of the code.”

Let’s take this random gist as an example. Click on the “view raw” button. Use <include text "..."> to transclude it:

(setq abg-elisp-external-dir
      (expand-file-name "external" abg-elisp-dir))

; ...

; Add external projects to load path
(dolist (project (directory-files abg-elisp-external-dir t "\\w+"))
  (when (file-directory-p project)
    (add-to-list 'load-path project)))

Actually, I added an Emacs Wiki feature using two lines of code that add support for fancy inclusion:

<include gist "https://gist.github.com/1236665">

It only works over there, however. See EmacsWiki:Gists.

Anyway, the same also works for Lisppaste:

<include text "http://paste.lisp.org/display/134703/raw">

Results in:

;; Set XTERM resources as so
;; metaSendsEscape: false
;; altSendsEscape: false
;; eightBitInput: true

;; Verify with cat > /dev/null command that pressing alt-a
;; alt-b and so on produces single >128bit char (will look
;; like a with a hat

;; once above is working in emacs do

;; Prevent pressing esc O from triggering binding
(define-key (get-input-decode-map) "\eO" nil)

;; tell emacs Meta is 8th bit
(cond ((fboundp 'set-input-meta-mode)
      (set-input-meta-mode t))
    (t (set-input-mode t nil t)))

I don’t think there’s a nice way to include the colored version, unfortunately.

Update: I added support and minimal Lisp highlighting for the following:

<include lisppaste "http://paste.lisp.org/display/134703">

It only works over there, of course.


Add Comment

2012-10-03 Search and Replace

I was looking at tabular data on a wiki page:

|[[...]]     |   1 |          6563|     3796|   |[[...]] | — |
|[[...]]     | 1/3 |          2315|     1259|   |[[...]] | — |
|[[...]]     | 1/3 |           159|      607|   |[[...]] | — |
|[[...]]     | 1/3 |           159|      597|   |[[...]] | — |

I wanted to add 56 to some of the values in the third column.

Emacs to the rescue: M-C-% to run query-replace-regexp and search for ^\(|[^|]*|[^|]*|[^|0-9]*\)\([0-9]+\) and replace it with \1\,(+ (string-to-number \2) 56)) – I was surprised at how easy it was once I had remembered to use \, in the replacement pattern.

Update: EmacsWiki:PierreGaston tells me that I could have used \#2 instead of (string-to-number \2). I guess I should have finished reading that paragraph on the Info page. ;)

Tags: RSS

Add Comment


Show Google +1

EditNearLinks: rcircRandomNames rcirc rcircColoredNicks

The same page on other sites: