2012-07-06

Emacs Lisp: Adding Your Package to MELPA

Emacs 24's package system is hot. It spreads a few hundred packages to every emacs user. (In GNU emacs, 41 packages (not counting built-in ones). With MELPA, 307 packages.) Before this, it takes years of emacs experience to know what packages are out there that are actually usable.

So, if you have written a package, putting it into a package repository would greatly increase your user base. I haven't done it yet myself, but here's a tutorial from Jon-Michael Deldin.

MELPA is pretty easy (https://github.com/milkypostman/melpa#contributing-new-packages) after you do it once.

  1. Fork the MELPA repository on GitHub
  2. Create a new file in the “recipes” directory with the right format. It's really easy — just take a look at an example recipe (https://github.com/milkypostman/melpa/blob/master/recipes/ir-black-theme).
  3. Test it with the ./buildpkg script and do M-x package-install-file
  4. On GitHub, visit your fork and click the Pull Request button

That's pretty much it. Marmalade is a little easier (just upload a tar or .el), but you have to upload a new version for each release.

2012-07-05

Lisp Syntax Readable?

lisp syntax is really unreadable. 10 years ago, i thought it's more of a joke for those uninitiated. But then surely the basic fact of uniformity is a problem for reading (because in nature, things are not uniform). But now having coded lisp for ≈5 years, i do find it comparatively unreadable.

here's sample code am currently reading.

(defun kill-new (string &optional replace yank-handler)
  "Make STRING the latest kill in the kill ring.
…"
  (if (> (length string) 0)
      (if yank-handler
          (put-text-property 0 (length string)
                             'yank-handler yank-handler string))
    (if yank-handler
        (signal 'args-out-of-range
                (list string "yank-handler specified for empty string"))))
  (unless (and kill-do-not-save-duplicates
               ;; Due to text properties such as 'yank-handler that
               ;; can alter the contents to yank, comparison using
               ;; `equal' is unsafe.
               (equal-including-properties string (car kill-ring)))
    (if (fboundp 'menu-bar-update-yank-menu)
        (menu-bar-update-yank-menu string (and replace (car kill-ring)))))
  (when save-interprogram-paste-before-kill
    (let ((interprogram-paste (and interprogram-paste-function
                                   (funcall interprogram-paste-function))))
      (when interprogram-paste
        (dolist (s (if (listp interprogram-paste)
                       (nreverse interprogram-paste)
                     (list interprogram-paste)))
          (unless (and kill-do-not-save-duplicates
                       (equal-including-properties s (car kill-ring)))
            (push s kill-ring))))))
  (unless (and kill-do-not-save-duplicates
               (equal-including-properties string (car kill-ring)))
    (if (and replace kill-ring)
        (setcar kill-ring string)
      (push string kill-ring)
      (if (> (length kill-ring) kill-ring-max)
          (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))))
  (setq kill-ring-yank-pointer kill-ring)
  (if interprogram-cut-function
      (funcall interprogram-cut-function string)))

Even though i hate Perl, but when perl script is well-coded, it's still more readable than lisp.

See also: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations.

2012-07-04

Emacs Key Macro and Elisp Exercise: Reformat XML

2012-07-02, Mihamina Rakotomandimby posted a interesting problem (Source groups.google.com):

I got a big one line XML file. I want to break the lines to make it more readable.

Replacing "><" with "C-j" then indenting is the most obvious solution, but would you know a more elegant solution?

This is a good exercise for emacs a keyboard macro. Record a key macro, save it, assign it a key. So, just press one key, and the file is indented and well-formatted.

to indent, just select all then call indent-regionCtrl+Alt+\】.

For key macro tutorial, see: Emacs: Using Keyboard Macro to Record/Playback Keystrokes.

or, if you are a emacs expert but never done any elisp, this is a great exercise. Write a command that does this. It's about 5 lines of elisp. (➲ Emacs Lisp Examples ₁)

2012-07-03

Emacs bug: Inserting French Quotation Mark

Perm URL with updates: http://ergoemacs.org/emacs/emacs_bugs.html

Steps to reproduce:

  1. Start emacs by: emacs -Q.
  2. Evaluate this: (global-set-key (kbd "<kp-8>") "«").
  3. Now, press the 8 on numerical keypad.
  4. Expected result: the french open quote is inserted. However, you get this error:
After 0 kbd macro iterations: Keyboard macro terminated by a command ringing the bell

Note that the following all work:

(global-set-key (kbd "<kp-8>") "「")
(global-set-key (kbd "<kp-8>") "『")
(global-set-key (kbd "<kp-8>") "〈")
(global-set-key (kbd "<kp-8>") "《")
(global-set-key (kbd "<kp-8>") "“")
(global-set-key (kbd "<kp-8>") "‘")
(global-set-key (kbd "<kp-8>") "‹")
(global-set-key (kbd "<kp-8>") "〔")

GNU Emacs 24.1.1 (i386-mingw-nt6.1.7601) of 2012-06-10 on MARVIN

2012-07-01

Queen - Bohemian Rhapsody

«Galaxy Nexus and Google+ Hangouts: Bohemians»

Cute girls. Cute.

Now, the real version. A fantastic song. Fantasmagorical.

“Queen - Bohemian Rhapsody” amazon

But, half of the charm lies in the lyrics. see: http://xahlee.org/music/Bohemian_Rhapsody.html

The song is written and sung by Freddie Mercury. he died of AIDS, in 1991 (age 45).

copy/paste in Linux X11 and emacs 24

In linux, if copy/paste doesn't work with other apps, you need to add this line:

(setq x-select-enable-clipboard t)

in GNU Emacs 24.0.93.1, that var is set to t now.

In X11 (Linux), there are basically 2 major copy/paste mechanisms: ① primary selection. ② clipboard. By convention, when you select a text using mouse, the text is automatically put into the primary selection, and middle click will paste it. The “X11's clipboard” is similar to the clipboard in Mac or Windows. You copy/paste by menu or keyboard. The primary selection and clipboard are independent.

Perm URL with updates: http://ergoemacs.org/emacs/emacs24_features.html