(add-to-list 'load-path (expand-file-name "~/.elisp/"))
;; Use cperl-mode instead of the default perl-mode
(add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
(autoload 'javascript-mode' "javascript" nil t)
(autoload 'php-mode' "php-mode" nil t)
(autoload 'css-mode' "css-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))
(add-to-list 'auto-mode-alist '("\\.php\\'" . php-mode))
(add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode))
;;Steve Yegge's suggestions
(global-set-key "\C-w" 'delete-backward-char)
(global-set-key "\C-x\C-k" 'kill-region)
(global-set-key "\C-c\C-k" 'kill-region)
;lose the UI
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(global-set-key "\C-x\C-m" 'execute-extended-command)
(global-set-key "\C-c\C-m" 'execute-extended-command)
;;WGE refers to Writing GNU Emacs Extensions
;traversing window functions (WGE Chapter 2)
(defun other-window-backward (&optional n)
"Move the focus to nth previous window."
(interactive "P")
(other-window (- (prefix-numeric-value n))))
(global-set-key "\C-xn" 'other-window)
(global-set-key "\C-xp" 'other-window-backward)
;scrolling functions for scrolling one line at a time (WGE Chapter 2)
(defalias 'scroll-ahead 'scroll-up)
(defalias 'scroll-behind 'scroll-down)
(defun scroll-n-lines-ahead (&optional n)
"scroll ahead n lines"
(interactive "P")
(scroll-ahead (prefix-numeric-value n)))
(defun scroll-n-lines-behind (&optional n)
"scroll ahead n lines"
(interactive "P")
(scroll-behind (prefix-numeric-value n)))
(defun scroll-n-lines-left (&optional n)
"scroll left n lines"
(interactive "P")
(scroll-left (prefix-numeric-value n)))
(defun scroll-n-lines-right (&optional n)
"scroll left n lines"
(interactive "P")
(scroll-right (prefix-numeric-value n)))
(global-set-key "\C-z" 'scroll-n-lines-behind)
(global-set-key "\C-q" 'scroll-n-lines-ahead)
(global-set-key "\C-\M-a" 'scroll-n-lines-left)
(global-set-key "\C-\M-s" 'scroll-n-lines-right)
(global-set-key "\C-c\C-q" 'quoted-insert)
;defining desired behaviour when opening a symlink file(WGE Chapter 2)
(add-hook 'find-file-hooks
(lambda ()
(if (file-symlink-p buffer-file-name)
(progn
(setq buffer-read-only t)
(message "File is a symlink")))))
(defun visit-target-instead ()
"Replace this buffer with a buffer visiting the link target"
(interactive)
(if buffer-file-name
(let ((target (file-symlink-p buffer-file-name)))
(if target
(find-alternate-file target)
(error "Not visiting a symlink")))
(error "Not visiting a file")))
(defun clobber-symlink ()
"Replace symlink with a copy of the file"
(interactive)
(if buffer-file-name
(let ((target (file-symlink-p buffer-file-name)))
(if target
(if (yes-or-no-p (format "Replace %s with %s?" buffer-file-name target))
(progn
(delete-file buffer-file-name)
(write-file buffer-file-name)))
(error "Not visiting a symlink")))
(error "Not visiting a file")))
;undoing scrolling (WGE Chapter 3)
(defvar unscroll-point nil
"Cursor position for next call to 'unscroll'.")
(defvar unscroll-window-start nil
"Window start for next call to 'unscroll'.")
(defadvice scroll-up (before remember-for-unscroll
activate compile)
"Remember where we started from, for 'unscroll'."
(if (not (eq last-command 'scroll-up))
(progn
(setq unscroll-point (point))
(setq unscroll-window-start (window-start)))))
(defun unscroll ()
"Jump to the position specified by 'unscroll-to'."
(interactive)
(if (and (not unscroll-point) (not unscroll-window-start))
(error "cannot unscroll yet"))
(progn
(goto-char unscroll-point)
(set-window-start nil unscroll-window-start)))
(global-font-lock-mode t)
(menu-bar-enable-clipboard)
(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.
'(show-paren-style (quote mixed)))
(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.
)