weblog d’un abbe


From an Emacs Lisp n00b

Filed under: Hacking — abbe @ 1219

Emacs Lisp, a dialect of LISP used by Emacs category of Operating Systems, is a cool language to learn. Yesterday, while trying to figure, what to do to test my n00b Emacs Lisp skills, I got this idea. As, I’d used Borland C/C++ IDE for around 5 years during 10+2 days, and I became addicted to its key bindings. Later, when I started using Emacs in 2003, I felt the problem of key bindings, which are totally different, like Alt+W to copy text, and Ctrl-Y to paste text. But that time, I felt lazy to learn Emacs customization stuff, so I decided to learn Emacs keybindings. But, yesterday I decided to implement some of the Borland IDE key bindings to my Emacs, so I hacked following Emacs Lisp code for my ~/.emacs.

;; Author: Ashish Shukla 
(defun enable-mode-if-disabled (modename)
  "Enables mode 'modename' if disabled"
  (if (not (eval modename))
	  (funcall modename)))

(defun compile-current-file()
  "Compiles current file (only for `emacs-lisp-mode')"
	  (not (eq buffer-file-name nil))
	  (if (eq major-mode 'emacs-lisp-mode)
		  (byte-compile-file buffer-file-name))))

(defun execute-current-file()
  "Executes current file (only for `emacs-lisp-mode')"
	  (and (not (eq buffer-file-name nil)) (eq major-mode 'emacs-lisp-mode))
	  (load-file buffer-file-name)))

(defun describe-current-word()
  "Describes `current-word', if it is defined as symbol"
  ;; intern-soft the current-word to see if a symbol exists
  ;; with this name.
  (if (not (eq (intern-soft (current-word)) nil))
	  ;; cool symbol exists, so retrieve the symbol
	  (let ((sym (intern (current-word))))
		;; if it is a 'function'
		(if (functionp sym)
			;; then describe function
			(describe-function sym)
		  ;; else describe variable
		  (describe-variable sym)))))

;; Borland Turbo C bindings
;; nothing special for C hackers, but Emacs LISP hackers
;; F2 - Save Buffer
(global-set-key [f2] 'save-buffer)
;; F3 - Load Buffer
(global-set-key [f3] (key-binding (kbd "C-x C-f")))
;; F5 - Execute currently loaded LISP file
(global-set-key [f5] 'execute-current-file)
;; F6 - Switch to other window
(global-set-key [f6] (key-binding (kbd "C-x o")))
;; F9 - Compile currently loaded LISP file to bytecode
(global-set-key [f9] 'compile-current-file)

;; not a Borland Turbo C keybinding
;; F7 - Describes current-word in Help window
(global-set-key [f7] 'describe-current-word)

(enable-mode-if-disabled 'font-lock-mode)
(enable-mode-if-disabled 'transient-mark-mode)
(enable-mode-if-disabled 'global-font-lock-mode)
(enable-mode-if-disabled 'show-paren-mode)
(enable-mode-if-disabled 'tooltip-mode)

(enable-mode-if-disabled 'line-number-mode)
(enable-mode-if-disabled 'column-number-mode)

(if (eq window-system nil)
	(enable-mode-if-disabled 'xterm-mouse-mode))


(set-face-foreground 'default "white")
(set-face-background 'default "black")

(if (eq window-system 'x)
	 "-b&h-luxi mono-medium-r-normal--*-95-100-100-m-0-iso10646-1"))

(setq default-tab-width 4)

Anyone interested in learning Emacs Lisp can try out similar stuff. Anyways, happy Emacs-ing ;)


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: