First step of my journey for rediscovering the straight path (aka I’m using again GNU Emacs after many years)

“… mi ritrovai per una selva oscura, ché la diritta via era smarrita …” (Divina Commedia – Canto I)

gnu_danteLike Dante in his allegoric journey, I (also) “found myself deep in a darkened forest, for I had lost all trace of the straight path” in the computing world.

The “darkened forest” in which I found myself is the world of proprietary software, in fact I found myself using some of the wrong (as in closed source) operating systems, programming languages and text editors. Sometimes there is no alternative in using proprietary software (i.e. a compiler for a strange architecture, a library that I absolute need to use for my daytime job).

But why I wasn’t using free software for the operating system and (even more) the text editor when there are the free software alternatives, and many of them are also technically better (way better), than the proprietary software I was using? That’s simple I just followed the hype.

For few years I had been using (and struggling with) the new, most popular, text editor. It is proprietary software. For years I didn’t use any full featured text editor: if I had to edit a configuration file I could use vi, for big (or not so big) software project I used NetBeans (developing mostly in C++); then, few years ago, I needed again a rich editor when I was writing longer scripts or working on projects developed in other programming languages (not supported by NetBeans).  I found this minimalistic, multi-platform, new (and not very stable at the time) text editor, I made few customization, I kept using it; nowadays it is very popular, everybody that wants or pretends to be cool use it.

Couple of days ago I was again struggling with the text editor, so I decided to look for a better alternative, and with better I mean at least comparable technically (rich in features, customizable, portable) and free software.

For years I used the best, as in full featured, customizable, extensible and portable text editor: GNU Emacs. I just forgot it!

I installed it on my office’s workstation (running Fedora), I retrieved my old configuration file (.emacs) and revised it. I found out that third party packages and customizations are not needed anymore because they are part of the mainstream distribution, so my new .emacs is cleaner and lighter than it was long time ago.

Please take a look below to the screenshot of my GNU Emacs running on Fedora 21 and my current .emacs configuration. If you wish you can download and use my .emacs.

GNU Emacs running on Fedora 21
GNU Emacs running on Fedora 21
;; enable package manager
(require 'package) 
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/") t)
(when (< emacs-major-version 24)
  (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize)
; and install required packages
(package-install 'monokai-theme)
(package-install 'projectile)
(package-install 'project-explorer)
(package-install 'smart-tab)

;; projectile and project explorer 
(require 'projectile)
(projectile-global-mode)
(require 'project-explorer)
(global-set-key "\M-p" 'project-explorer-open)  ; open the sidebar containing
                                                ; containing the project
                                                ; structure

;; global interface customization
(setq inhibit-startup-message t) ; I know this is Emacs
(fset 'yes-or-no-p 'y-or-n-p)    ; y for 'yes', n for 'no'
(setq column-number-mode t)      ; show the column number in the modeline
(setq query-replace-highlight t) ; highlight matches when using replace
(show-paren-mode t)              ; highlight matching parenthesis
(flyspell-prog-mode)             ; spell checking for comments and strings 
(electric-pair-mode)             ; insert automatically matching parenthesis
(electric-layout-mode)           ; let the editor insert automatically spaces
                                 ; and new lines when appropriate
(setq font-lock-maximum-decoration t)  ; use all the font decoration

;; global key bindings
(global-set-key "\C-c\C-g" 'goto-line)         ; Move to specified line
(global-set-key "\M-q" 'comment-region)        ; Comment selected text
(global-set-key "\M-e" 'uncomment-region)      ; Uncomment selected text
(global-set-key "\M-w" 'delete-other-windows)  ; Hide other windows

;; Enable tab completion
(require 'smart-tab)
(global-smart-tab-mode 1)

;; Disable the bell for specific functions, such as when trying to scroll beyond
;; the end of the buffer
(defun my-bell-function ()
  (unless (memq this-command
                '(isearch-abort abort-recursive-edit exit-minibuffer
                                keyboard-quit mwheel-scroll down up next-line
                                previous-line backward-char forward-char
                                scroll-down-command scroll-up-command))
    (ding)))
(setq ring-bell-function 'my-bell-function)

;; Buffer switching customizaation
; Ignore Emacs' generated buffer when switching buffers
(defadvice next-buffer (after avoid-messages-buffer-in-next-buffer)
  (when (string-match "^\\*" (buffer-name))
    (next-buffer)))
(ad-activate 'next-buffer)

(defadvice previous-buffer (after avoid-messages-buffer-in-previous-buffer)
  (when (string-match "^\\*" (buffer-name))
    (previous-buffer)))
(ad-activate 'previous-buffer)

; Use M-a, M-d to switch to the previous or to the next buffer
(global-set-key "\M-a" 'previous-buffer)
(global-set-key "\M-d" 'next-buffer)

;; Use F5 to re-evaluate on the fly .emacs
(add-hook 'emacs-lisp-mode-hook
          (lambda () (local-set-key (kbd "<f5>") 'eval-buffer))
          )

;; console specific customization
(defun console-interface()
  (menu-bar-mode -1)      ; remove the menu bar
  (display-time-mode)     ; display time
  (require 'battery)      
  (display-battery-mode)  ; display battery level
  )

;; X11 specific customization
(defun x-interface()
  (require 'monokai-theme)  ; nice dark theme
  (cua-mode)                ; Usual copy/cut/paste
  (tool-bar-mode -1)        ; hide useless toolbar
  (global-hl-line-mode)     ; highlight current line
  )

;; Mac specific customization
(defun mac-interface()
  (x-interface)  ; use the X11 customization
  (setq-default ispell-program-name "/usr/local/bin/ispell")  ; ispell path
  (set-face-attribute 'default nil :font "Monaco")  ; default font
  ; enabling CMD+{right,left,up,down} for end, home, pgup, pgdown
  (global-set-key (kbd "<s-right>") 'move-end-of-line)     
  (global-set-key (kbd "<s-left>") 'move-beginning-of-line)
  (global-set-key (kbd "<s-up>") 'scroll-down-command)
  (global-set-key (kbd "<s-down>") 'scroll-up-command)  
  )

;; Apply window system specific customization
(if (not window-system)
    (console-interface)
  )
(if (eq window-system 'x)
    (x-interface)
  )
(if (eq window-system 'ns)
    (mac-interface)
  )

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s