Habibullah’s posterous

October 21, 2008

.el files I use

I have attached some "plugins" that I use while programming Lisp in Emacs. They are:
slime, url. acldoc, color-theme, hl-sexp, mic-paren, mwe-log-commands, paredit and tabbar.

Click here to download:
Archive.tar.gz (998 KB)

Comments [0]



October 15, 2008

Refer to CL documentation from within Emacs

While programming in Common Lisp I feel the need to refer to the documentation time and again. As I'm very lazy (a positive trait mind you), I don't want to browse to /usr/local/acl81/doc, wait for Firefox to load, then click on the index, then search for the symbol you want and click on it.

Okay, it's not such a long procedure but it is a distraction nonetheless. And why can't this procedure be somewhat shorter?

Turns out I'm just following the path of other lazy programmers.

Slime and acldoc can help us here.

If you are programming in ANSI Common Lisp then you can't go wrong with the LispWorks Common Lisp HyperSpec.

If you are programming with Allegro Common Lisp and utilize their extensions to CL, you will need to refer to the Allegro documentation. Heck, you can refer to both if you so desire.

The CL documentation isn't going to change rapidly. So it makes sense to cache the documentation onto your local hard disk instead of referring to the web-site for every request. Where I stay this has an added benefit of not getting frustrated with the pathetic load times.

Here's how you go about accessing the HyperSpec from within Emacs:

1) Download the HyperSpec from here, and extract it to your favourite location.

2) Open your .emacs file and type in:
(setq common-lisp-hyperspec-root "path/to/HyperSpec/")
(setq common-lisp-hyperspec-symbol-table (concat common-lisp-hyperspec-root "Data/Map_Sym.txt"))
where "/path/to/HyperSpec/" is where you have extracted it.

3) After you've started Slime, put the point on the symbol you want and press C-c C-d h to pop-up the documentation in a new browser window.

Here's how you go about accessing the ACL docs from within Emacs. It's a little more involved, but the results are beautiful!

1) The Free Express edition doesn't come with documentation. You can download it from here.

2) If you are using the Professional edition, then the documentation is stored in a sub-folder called doc where ACL is installed. Put this in your .emacs file:
;;The location of ACL docs
(setq acldoc-local-root "/usr/local/acl81/")
(setq acldoc-use-local t)

3) Then you need to get url.el and it's dependants. If you are using Emacs 22 or above, then you already have it. Say hurray and skip to step 5.

4) Download the tar.gz from the bottom of this post and untar it to your favourite location. Then add to your .emacs file:
(add-to-list 'load-path "/path/to/url/")
You know what to do with "/path/to/url/".

5) Type in your .emacs file:
(require 'url)

6) Now you need acldoc. Get it from here, and copy the contents to a file called acldoc.el. Put in your .emacs file:
(add-to-list 'load-path "/path/to/acldoc/")
(require 'acldoc)

7) Congrats! Now you can refer to the ACL docs by typing:
M-x acldoc
and then the name of the symbol. If you are still lazy then add the following shortcut to your .emacs file:
;;Press C-F1 with the cursor on a symbol and then press Enter to get the ACL docs for the given symbol.
(global-set-key [(control f1)] 'acldoc)

Okay, things aren't quite as hunky-dory as they might seem. Some html files are displayed in the Emacs buffers. I tried to figure out the why behind the extra files, but I was feeling rather dense today. So I cheated. Since I have ample RAM and processing power, I don't care if a few extra buffers get opened up. So I put them out of sight using Tabbar. Take a look at the Tabbar section of my .emacs file to see what I did.

Hint: It's something to do with the major mode.

Enjoy!

Click here to download:
url.tar.gz (71 KB)

Comments [0]



October 10, 2008

Tramp

Today I configured Tramp. Tramp allows you to SCP or SSH to remote servers and create and edit files as another user, all through Emacs. This link will take you to the official site. I don't need to expound upon how useful this feature is :)

I have updated my .emacs file filled with new Tramp goodness!

Tramp comes with GNU Emacs 22 onwards. If you are using 21.4, or previous, you have a few steps to perform before you can use Tramp.
  1. Download Tramp.
  2. Extract to a temporary location.
  3. Run ./configure
  4. Run make
  5. Run make install
  6. In your .emacs file add the following code and then save and restart emacs:
    (require 'tramp)

    (setq tramp-default-method "ssh")
  7. To access a file on a remote server:
    C-x C-f /remotehost:filename RET (or /method:user@remotehost:filename)

Comments [0]



October 08, 2008

Commands supported by ACL

A brief list of Allegro CL commands is available here.

In particular, today this link turned out to be really helpful for me.

Comments [0]



October 07, 2008

My .emacs file

Here is my .emacs file.

;;All the "plugins" are kept in this folder except the ones that are split over more than 1 .el file.
(add-to-list 'load-path "~/LispDev/")

;;Set the default font
(set-default-font "9x15")

;;Set scroll bar to appear on the right
(setq scroll-bar-mode-explicit t)
(set-scroll-bar-mode 'right)

;;Uniquify buffer names: Append path if buffer names are identical
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)

;;Specify modes for Lisp file extensions so that we can turn on syntax
;;highlighting for Lisp files with non-standard extensions
(setq auto-mode-alist
      (append '(("\.lisp$"   . lisp-mode)
        ("\.lsp$"    . lisp-mode)
        ("\.cl$"     . lisp-mode)
        ("\.asd$"    . lisp-mode)
        ("\.system$" . lisp-mode)) auto-mode-alist))

;;There are 2 ways to interact with Lisp from within Emacs.
;;The first one uses the ACL ELI (Emacs Lisp Interaction) provided by Allegro.
;;The second one, that I prefer to use, is SLIME (Superior Lisp Interaction Mode for Emacs)
;;I have commented out ELI and kept SLIME. You can keep both if you prefer.


;;Begin ELI
;; ACL ELI stuff that is to be ignored, for now.
;; ;; Setting up the ACL ELI (Allegro Common Lisp's Emacs Lisp Interface)
;; (load "/usr/local/acl81/eli/fi-site-init")

;; ;; These are the inputs to the run-common-lisp function
;; (setq fi:common-lisp-image-name "/usr/local/acl81/mlisp")
;; (setq fi:common-lisp-host "localhost")
;; (setq fi:common-lisp-directory "~/")

;; ;; This function starts up lisp with your defaults.
;; (defun run-common-lisp ()
;;   (interactive)
;;   (fi:common-lisp fi:common-lisp-buffer-name
;;                   fi:common-lisp-directory
;;                   fi:common-lisp-image-name
;;                   fi:common-lisp-image-arguments
;;                   fi:common-lisp-host
;;                   fi:common-lisp-image-file))

;; ;; Pressing C-x-4-l will start up ACL from within Emacs
;; ;; Set up a keybinding for `run-common-lisp':
;; (progn
;;   (setq ctlx-4-map (make-keymap))
;;   (define-key ctl-x-map "4" ctlx-4-map)
;;   (define-key ctlx-4-map "l" 'run-common-lisp))

;; To auto-run the ELI when starting Emacs
;;(run-common-lisp)
;;End ELI

;;Begin SLIME
;;Update this path to the correct location.
(add-to-list 'load-path "~/LispDev/slime/")
(require 'slime-autoloads)

;;Disable the SLIME startup animation.
(setq slime-startup-animation nil)

(eval-after-load "slime"
  '(progn
     (add-to-list 'load-path "~/LispDev/slime/contrib/")
     (slime-setup '(slime-fancy slime-banner slime-presentations slime-tramp slime-asdf))
     (setq slime-complete-symbol*-fancy t)
     (setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol)))

;;Specify the Lisp program you are using. Default is "lisp"
;;If the Allegro directory is not in your PATH environment variable
;;this should be a fully qualified path.
;;choose one of the below based on Express or non-Express usage
;;(setq inferior-lisp-program "alisp")
(setq inferior-lisp-program "/usr/local/acl81/mlisp")

;;To use the ELisp indentation while programming in CL.   
(load "cl-indent")
(put 'if 'common-lisp-indent-function '(nil nil &body))
;;End SLIME

;;Download and extract the HyperSpec at a given location.
;;You can get the documentation from Habib or from here:
;;ftp://ftp.lispworks.com/pub/software_tools/reference/HyperSpec-7-0.tar.gz
;;Use the following code to point to the given location.
;;That way if you work offline, you can still access the HyperSpec.
(setq common-lisp-hyperspec-root "~/LispDev/docs/HyperSpec/")
(setq common-lisp-hyperspec-symbol-table (concat common-lisp-hyperspec-root "Data/Map_Sym.txt"))

;;Download and extract CLtL2 at a given location.
;;It is available in the FTP.
;;Use the following code to point to the given location.
;;That way if you work offline, you can still access CLtL2
(setq cltl2-url "file:///home/habib/LispDev/docs/cltl/clm/node1.html")

;;Add the URL and ACLDOC paths to see the ACL documentation in a new browser window
;;If you are using Emacs 22 and above, no need for the following line. It is only needed in Emacs 21.x
(add-to-list 'load-path "~/LispDev/url/")
(require 'url)
(require 'acldoc)

;;The location of ACL docs
(setq acldoc-local-root "/usr/local/acl81")
(setq acldoc-use-local t)

;;Press C-F1 with the cursor on a symbol and then press Enter to get the ACL docs for the given symbol.
;;Or you can type M-x acldoc with the point on the chosen symbol.
(define-key lisp-mode-map (kbd "C-c a") 'acldoc)

;;By default, the Enter key will just take you to a new-line.
;;After that you have to press Tab to get the correct indentation.
;;Add a hook that will redefine the Enter key to be 'newline-and-indent.
;;That way you don't have to press Tab at the beginning of every line.
(add-hook 'lisp-mode-hook
      '(lambda ()
         (define-key lisp-mode-map [?\C-m] 'newline-and-indent)
         (define-key lisp-mode-map [?\C-j] 'newline)))

(custom-set-variables
 ;;custom-set-variables was added by Custom -- don't edit or cut/paste it!
 ;;Your init file should contain only one such instance.
 '(auto-compression-mode t nil (jka-compr))
 '(blink-matching-paren-on-screen t)
 '(case-fold-search t)
 '(case-mode "case-insensitive-lower")
 '(compilation-mode-hook nil t)
 '(current-language-environment "English")
 '(debug-on-error t)
 '(default-input-method "rfc1345")
 '(easy-menu-precalculate-equivalent-keybindings t)
 '(global-font-lock-mode t nil (font-lock))
 '(save-place t nil (saveplace))
 '(show-paren-mode t nil (paren))
 '(show-paren-style (quote mixed))
 '(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
 '(transient-mark-mode t))

;;My chosen background is black and chosen text colour is white. You can change that here:
(custom-set-faces
 ;;custom-set-faces was added by Custom -- don't edit or cut/paste it!
 ;;Your init file should contain only one such instance.
 '(default ((t (:stipple nil
        ;;:background "black"
        :background "gray10"
        :foreground "white"
        :inverse-video nil
        :box nil
        :strike-through nil
        :overline nil
        :underline nil
        :slant normal
        :weight normal
        :width normal))))
 '(show-paren-match-face ((((class color)) (:bold t :background "red")))))

(put 'downcase-region 'disabled nil)

(setq standard-indent 2)
(mouse-wheel-mode t)

;;Show line-number in the mode line
(line-number-mode 1)

;;Show column-number in the mode line
(column-number-mode 1)

;;Disables the starting 'splash' screen of Emacs
(setq inhibit-startup-message t)

(setq font-lock-maximum-decoration t)

;;Begin Tabbar
;;Tabbar will show tabs in Emacs allowing you to click and goto a particular tab. Quite useful!
(require 'tabbar)
(tabbar-mode 1)
(global-set-key [(control shift up)]    'tabbar-backward-group)
(global-set-key [(control shift down)]  'tabbar-forward-group)
(global-set-key [(control shift left)]  'tabbar-backward)
(global-set-key [(control shift right)] 'tabbar-forward)

(set-face-attribute
 'tabbar-default-face nil
 :background "gray60")
(set-face-attribute
 'tabbar-unselected-face nil
 :background "gray85"
 :foreground "gray30"
 :box t)
(set-face-attribute
 'tabbar-selected-face nil
 :background "white"
 :foreground "black"
 :box nil)
(set-face-attribute
 'tabbar-button-face nil
 :box '(:line-width 8 :color "gray72" :style released-button))
(set-face-attribute
 'tabbar-separator-face nil
 :height 0.7)

(defun tabbar-buffer-groups (buffer)
  "Return the list of group names BUFFER belongs to.
Return only one group for each buffer."
  (with-current-buffer (get-buffer buffer)
    (cond
     ((or (get-buffer-process (current-buffer))
          (memq major-mode
                '(comint-mode compilation-mode)))
      '("Misc")
      )
     ((member (buffer-name)
              '("*scratch*"))
      '("Main")
      )
     ((member (buffer-name)
              '("*Messages*"))
      '("Misc")
      )
     ((eq major-mode 'dired-mode)
      '("Main")
      )
     ((memq major-mode
            '(fundamental-mode help-mode apropos-mode Info-mode Man-mode))
      '("Misc")
      )
     ((memq major-mode
            '(tex-mode latex-mode text-mode xml-mode))
      '("Main")
      )
     ((memq major-mode
            '(rmail-mode
              rmail-edit-mode vm-summary-mode vm-mode mail-mode
              mh-letter-mode mh-show-mode mh-folder-mode
              gnus-summary-mode message-mode gnus-group-mode
              gnus-article-mode score-mode gnus-browse-killed-mode))
      '("Mail")
      )
     ((memq major-mode
            '(html-mode))
      '("HTML")
      )
     (t
      '("Main")
      )
     )))
;;End Tabbar

;;Begin Tramp
;;Tramp allows you to access a remote file from within your Emacs over a secure SSH link.
;;Download and install tramp if you are using Emacs 21.4. I think it's already present in Emacs 22 and above.
;;(require 'tramp)
;;(setq tramp-default-method "ssh")
;;End Tramp

;;hl-sexp-mode highlights the s-expression containing point.
(require 'hl-sexp)
(autoload 'hl-sexp-mode "hl-sexp"
  "Minor mode to highlight s-expression at point."
  t)

(require 'mic-paren)
(paren-activate)

;;Begin Paredit
;;Paredit will turn Emacs into a "structured text editor". You manipulate s-expressions, and not lines of text.
;;It also keeps all your parentheses nicely balanced.
;;Install paredit by placing `paredit.el' in `/path/to/elisp', a
;;directory of your choice, and adding to your .emacs file:
(require 'paredit)
(autoload 'paredit-mode "paredit"
 "Minor mode for pseudo-structurally editing Lisp code."
  t)

;;Toggle Paredit Mode with `M-x paredit-mode', or enable it
;;always in a major mode `M' (e.g., 'lisp' or 'scheme') with along with others:
(mapc (lambda (mode)
    (let ((hook (intern (concat (symbol-name mode)
                    "-mode-hook"))))
      (add-hook hook (lambda ()
               (paredit-mode +1)
               (paren-toggle-matching-quoted-paren 1)
               (paren-toggle-matching-paired-delimiter 1)
               (hl-sexp-mode +1)))))
     '(emacs-lisp lisp inferior-lisp slime slime-repl repl))
;;End Paredit

;;Begin lispdoc search engine
(defun lispdoc ()
  "Searches lispdoc.com for SYMBOL, which is by default the symbol
currently under the cursor"
  (interactive)
  (let* ((word-at-point (word-at-point))
         (symbol-at-point (symbol-at-point))
         (default (symbol-name symbol-at-point))
         (inp (read-from-minibuffer
               (if (or word-at-point symbol-at-point)
                   (concat "Symbol (default " default "): ")
         "Symbol (no default): "))))
    (if (and (string= inp "") (not word-at-point) (not
                           symbol-at-point))
        (message "you didn't enter a symbol!")
      (let ((search-type (read-from-minibuffer
              "full-text (f) or basic (b) search (default b)? ")))
    (browse-url (concat "http://lispdoc.com?q="
                (if (string= inp "")
                default
                  inp)
                "&search="
                (if (string-equal search-type "f")
                "full+text+search"
                  "basic+search")))))))

;;Key-binding to search lispdoc.com for the given symbol at point.
(define-key lisp-mode-map (kbd "C-c l") 'lispdoc)
;;End lispdoc search engine

;;Will highlight the current line for you
;;(global-hl-line-mode 1)

;;Autostart Slime
;;(slime)

;;(add-to-list 'load-path "~/LispDev/color-theme-6.6.0/")
;;(require 'color-theme)
;;(color-theme-initialize)
;;(color-theme-gnome2)

Comments [0]



September 29, 2008

Tabs in Emacs

RMS (Richard M. Stallman for the un-initated) recently marvelled at the tabs in Eclipse. You can have something similar, albeit  old-school by installing Tabbar for Emacs. Emacs 21.4 on my work machine doesn't have it pre-installed although I think the newer versions of Emacs do contain Tabbar.

1) Download the tar.gz file from here. Extract the tabbar.el file to your desktop.

2) Start up Emacs, press M-x byte-compile-file and press Enter. Then type in the path to tabbar.el file. A new file called tabbar.elc will be created.

3) This tabbar.elc file now has to be put into your Emacs load path after probably becoming root. For my machine it is at:
/usr/share/emacs/21.4/lisp

4) Open up your .emacs file and put in:
;;Setting up tabbar
(require 'tabbar)
(tabbar-mode)

5) Restart Emacs and you should be set. The default look and feel of Tabbar is pretty ugly. (What did you expect?) So head onto Amit's blog to read how he went about customizing it.

Comments [0]



September 25, 2008

To Auto-start ACL when you start Emacs

To Auto-start Allegro Common Lisp when you start Emacs, do the following:

1) Add the lines to your .emacs file described here.

2) Comment out the C-x-3-l keybinding section that you've copy pasted above. i.e. note the difference in the code here and the one you've added.

;; Set up a keybinding for `run-common-lisp':
;;(progn
;;   (setq ctlx-3-map (make-keymap))
;;   (define-key ctl-x-map "3" ctlx-3-map)
;;   (define-key ctlx-3-map "l" 'run-common-lisp))

3) To run Allegro Common Lisp everytime you start emacs, add the following lines:
;; Run cl each time Emacs is run:
(run-common-lisp)

4) Save the buffer and restart Emacs. You should find a *common-lisp* buffer available to you.

5) In case you want to restore the key-binding, comment out the code you added in step 3 and uncomment the changes in step 2.

Comments [0]



September 25, 2008

Interact with Common Lisp from within Emacs

To start Allegro Common Lisp from within Emacs in Windows:

1) Generate mlisp.exe as explained in a previous blog post.

2) Copy paste the following code into your .emacs file:

(defvar *eli-directory*)                                                                                                                      
(setq *eli-directory* (expand-file-name "C:/Program Files/acl81-express/eli/"))

(when (and (not (string-match "xemacs" emacs-version))
           (= emacs-major-version 20)
           (<= emacs-minor-version 2))
   (setq load-path (cons *eli-directory* load-path)))

(load (format "%sfi-site-init.el" *eli-directory*))

(setq fi:common-lisp-image-name "C:/Program Files/acl81-express/mlisp.exe")

(setq fi:common-lisp-host "localhost")
(setq fi:common-lisp-directory "~/.")

;; This function starts up lisp with your defaults.
(defun run-common-lisp ()
  (interactive)
  (fi:common-lisp fi:common-lisp-buffer-name
                  fi:common-lisp-directory
                  fi:common-lisp-image-name
                  fi:common-lisp-image-arguments
                  fi:common-lisp-host
                  fi:common-lisp-image-file))

;; Set up a keybinding for `run-common-lisp':
(progn
  (setq ctlx-3-map (make-keymap))
  (define-key ctl-x-map "3" ctlx-3-map)
  (define-key ctlx-3-map "l" 'run-common-lisp))

3) Change *eli-directory* to where you have installed Allegro Common Lisp trial. I have installed it at the given location. You'll find mlisp.exe one folder above that.

4) Save the .emacs file and restart Emacs.

5) To start Allegro CL, press C - x - 3 - l

(That's lower case l at the end)

6) You'll find a new buffer *common-lisp* where you can interact with mlisp.exe from within Emacs. 

Comments [1]



September 25, 2008

Generating mlisp.exe in Allegro Common Lisp Trial edition

When you start Allegro Common Lisp's Trial version you are forced to deal with Lisp from within an IDE. Sometimes you might want the REPL prompt to load up faster and be free from the GUI clutter. For that you need to run mlisp.exe or if you don't want case sensitivity, then the ANSI Lisp image alisp.exe (on Windows ofcourse).

Unfortunately, these are available only in the paid version of Allegro Common Lisp and have to be generated.

This is how:
1) Start Allegro's IDE or allegro-express.exe

2) In the "Debug Window" listener, copy paste the following Lisp code:
;; mlisp:
   (progn
      (build-lisp-image "sys:mlisp.dxl" :case-mode
                                        :case-sensitive-lower
                                        :include-ide nil
                                        :restart-app-function nil
                                        :restart-init-function nil)
      (when (probe-file "sys:mlisp.exe") (delete-file "sys:mlisp.exe"))
      (sys:copy-file "sys:allegro-express.exe" "sys:mlisp.exe"))   

3) This will generate the mlisp.exe file that you can use. To generate alisp.exe replace mlisp with alisp in the above code.

I've taken the above code from the readme.txt file available with Allegro CL Trial and simplified it a bit for the newbies.

Happy Lisping!

Comments [0]



July 17, 2008

So Easy.

I love how easy it is creating and maintaining a blog at Posterous.

Comments [0]