Tips on coding Linden Scripting Language with Emacs

Xah Lee, 2007-03.

This page contains some tips on using the Linden Scripting Language with the Emacs text editor. (If you are not familiar with them, see LSL Tutorial or Emacs Tutorial. )

Copy, Cut, Paste, and Selection Highlight

First, turn on the CUA mode, under the menu “Options‣C-x/C-c/C-v Cut and Paste (CUA)”. Also, turn on “Options‣Paren Match Highlighting”, then select “Options‣Save Opitons”.

emacs basic options

The CUA mode will activate the shortcuts “Ctrl+x” for cut, “Ctrl+c” for copy, “Ctrl+v” for paste. Also, it will highlight when a region of a text is selected. And, when a text is selected, typing or pressing the Delete key will delete the selection. These are standard conventions.

Syntax Coloring

To make your LSL script automatically syntax colored, get this LSL-mode: lsl-mode.el. Follow the instructions in the file at top.

Reference Lookup

The following will let you lookup a word under cursor in a LSL reference site.

Add the following to your emacs customization file (“~/.emacs”).

(defun lsl-lookup ()
"Look up current word in Linden Scripting Language ref site in a browser.\n
If a region is active (a phrase), lookup that phrase."
 (interactive)
 (let (myword myurl myPos1 myPos2)
   (setq myword
         (if (and transient-mark-mode mark-active)
             (buffer-substring-no-properties (region-beginning) (region-end))
             (save-excursion
                (skip-chars-backward "_A-Za-z")
                (setq myPos1 (point))
                (skip-chars-forward "_A-Za-z")
                (setq myPos2 (point))
                (buffer-substring-no-properties myPos1 myPos2))))
   (setq myurl (concat "http://lslwiki.net/lslwiki/wakka.php?wakka=" myword))
; (setq myurl2 (concat "http://wiki.secondlife.com/wiki/" myword))
; (browse-url myurl2)
   (browse-url myurl)))

(global-set-key (kbd "<f5>") 'lsl-lookup)

With the above code, you can lookup LSL references quickly. Place your cursor on a keyword, then press F5, then emacs will launch your default web browser and open the LSL wiki page for that keyword.

Copying to Second Life

The process of editing in emacs and copy pasting to Second Life may get tedious. Here's some tips.

Press Alt-TAB to switch to the last application. (Cmd-TAB on the Mac).

In emacs, to select all is “C-x h” and copy is “Ctrl+c”. This is too many keystrokes. Put the following in your “~/.emacs” file. Then, you can copy the whole buffer's content by pressing “Alt+Shift+a”.

(defun copy-all ()
  "Put the whole buffer content into the kill-ring."
  (interactive)
  (kill-ring-save (point-min) (point-max))
  (message "Buffer content copied")
  )

(global-set-key [(meta shift a)] 'copy-all)

Also, learn the keyboard shortcuts in the Second Life client. For example, here are userful shortcuts when scripting in Second Life:


Related essay:


Page created: 2007-03.
© 2007 by Xah Lee.
Xah Signet