Albergue Valladolid
(setq truncate-lines t
      truncate-partial-width-windows t)

(fset 'yes-or-no-p 'y-or-n-p)

(add-hook 'minibuffer-setup-hook 
          (lambda () 
            (setq truncate-lines nil)))

(let ((path (split-string (getenv "PATH") ":")))
  (add-to-list 'path "/home/exal/scripts")
  (setenv "PATH" (mapconcat 'identity path ":")))

(setq-default inhibit-startup-message 't
              font-lock-use-fonts '(or (mono) (grayscale))
              font-lock-use-colors '(color)
              font-lock-maximum-decoration 't
              font-lock-maximum-size 'nil
              font-lock-auto-fontify 't
              global-font-lock-mode 't
              display-warning-minimum-level 'error
              paren-more 'sexp
              system-name "bernardita"
              exal-emacs-dir (expand-file-name "~/emacs-stuff/")
              user-full-name "Exal de Jesus  Garcia Carrillo"
              user-mail-address ""
              initial-major-mode 'text-mode
              display-time-day-and-date 't
              display-time-24hr-format 't
              column-number-mode 't
              initial-scratch-message 'nil
              mail-user-agent 'gnus-user-agent
              mouse-yank-at-point 't
              read-mail-command 'gnus
              printer-name "Dell"
              use-file-dialog 'nil)

(setq custom-file (expand-file-name "exal-custom.el" exal-emacs-dir))

(add-to-list 'exec-path "~/scripts")

;(add-hook 'after-save-hook '(lambda () (executable-make-buffer-file-executable-if-script-p)
;                                       (exal-eval-buffer)))

(dolist (dir 
         `("lisp" "emacs-stuff" "repos/gnus/lisp" "repos/emms/" 
           "repos/erc" "lisp/chess" "lisp/muse/lisp" "lisp/bbdb/lisp"
           "lisp/predictive" "repos/emacs-w3m"))
  (push (expand-file-name 
         (concat "~/" dir)) load-path))

(add-hook 'after-init-hook 'color-theme-exal-emacs)

;(require 'html-helper-mode)
;(setq html-helper-build-new-buffer nil)
;(setq html-helper-do-write-file-hooks t)

;(if (= emacs-major-version 23)
;        (require 'w3m-ems)
;  (require 'w3m))

  (autoload 'openpaste-region "openpaste")
  (define-key global-map (kbd "C-; p") 'openpaste-region)

(require 'easymenu)
(require 'boxquote)
(require 'color-theme)
(require 'redo)
(require 'exal-pwd)
(require 'exal-functions)
(require 'exal-skeletons)
(require 'exal-color-theme)
(require 'check-mail)
(require 'todoo)
(require 'autoinsert)
(require 'mule)
(require 'htmlize)
;(require 'tramp)
;(autoload 'acpi "acpi" nil t)

;; superego
;(autoload 'superego-mode "/home/exal/lisp/superego.el" nil t)

;(add-hook 'text-mode-hook 'superego-mode)
;(add-hook 'lisp-mode-hook 'superego-mode)
;(add-hook 'bash-mode-hook 'superego-mode)
;(add-hook 'fundamental-mode-hook 'superego-mode)
;(add-hook 'emacs-lisp-mode-hook 'superego-mode)
;(add-hook 'gnus-startup-hook 'superego-mode)
;(add-hook 'gnus-article-prepare-hook 'superego-mode)



(global-set-key [(control y)] 'redo)
(global-set-key [(control z)] 'undo)


(defun exal-backup-file-name (fpath)
  "Return a new file path of a given file path.
If the new path's directories does not exist, create them."
  (let (backup-root bpath)
    (setq backup-root "/home/exal/.emacsbackup")
    (setq bpath (concat backup-root fpath "~"))
    (make-directory (file-name-directory bpath) bpath)
(setq make-backup-file-name-function 'exal-backup-file-name)

;wget config stuff
(autoload 'wget "wget" "wget interface for Emacs." t)
(autoload 'wget-web-page "wget" "wget interface to download whole web page." t)

        (when window-system

  (when (locate-library "recentf")
    (setq recentf-save-file (expand-file-name "recentf" exal-emacs-dir)
          recentf-max-saved-items 100
          recentf-max-menu-items  20
          recentf-exclude '("/Gnus/" "\\`/[a-zA-Z0-9@]+:"))
    (require 'recentf)
    (recentf-mode 1))

;; encoding
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)   
(set-language-environment "utf-8") 

;; Paren highlight
(if (fboundp 'paren-set-mode)    ; Highlight the whole expression
  (paren-set-mode 'sexp)
  (setq show-paren-style 'expression)

;; Display time

 (cua-mode t)

 (setq CUA-mode-normal-cursor-color "red"
       CUA-mode-overwrite-cursor-color "yellow"
       CUA-mode-read-only-cursor-color "green")

;;;; Inferior lisp, etc

(if (executable-find "sbcl") (setq inferior-lisp-program "sbcl"))

  (setq inferior-lisp-program "sbcl")
  (autoload 'slime "slime" "" t)
  (add-hook 'lisp-mode-hook
              (lambda () 
                (slime t)
                (setq lisp-indent-function 'common-lisp-indent-function)))

  (add-hook 'inferior-lisp-mode-hook 
            (lambda () 
              (inferior-slime-mode t)))

;;; ElDoc

(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
(add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
(add-hook 'lisp-mode-hook 'turn-on-eldoc-mode)
(add-hook 'erc-mode-hook 'turn-on-eldoc-mode)

;; Save places in files.
(setq save-place-file (expand-file-name "places" exal-emacs-dir))

(setq version-control t
      backup-by-copying t  
      backup-directory-alist '(("~/.emacsbackup"))
      kept-old-versions 300
      kept-new-versions 2000
      delete-old-versions t)

(setq eval-expression-print-level  10
      eval-expression-print-length 100)

;;;  Web development modes and stuff


(require 'html-helper-mode)

(setq html-helper-build-new-buffer nil)
(setq html-helper-do-write-file-hooks t)
;(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
(setq auto-mode-alist (cons '("\\.html$" . html-mode) auto-mode-alist))

;; CSS
(autoload 'css-mode "css-mode")
(setq auto-mode-alist
  (cons '("\\.css\\'" . css-mode) auto-mode-alist))

;; PHP

(require 'php-mode)
(add-hook 'php-mode-user-hook 'turn-on-font-lock)

 (defvar hexcolour-keywords
      (0 (put-text-property (match-beginning 0)
                            (match-end 0)
                            'face (list :background 
                                        (match-string-no-properties 0)))))))
 (defun hexcolour-add-to-font-lock ()
   (font-lock-add-keywords nil hexcolour-keywords))

 (add-hook 'html-mode-hook 'hexcolour-add-to-font-lock)
 (add-hook 'css-mode-hook 'hexcolour-add-to-font-lock)
 (add-hook 'php-mode-hook 'hexcolour-add-to-font-lock)

(add-hook 'html-mode-hook
          (lambda ()
            (local-set-key [(control o) (t)] 'exal-html-temple)
            (local-set-key [(control o) (c)] 'exal-html-checkboxes)
            (local-set-key [(control o) (e)] 'exal-html-textarea)
            (local-set-key [(control o) (f)] 'exal-html-form)
            (local-set-key [(control o) (r)] 'exal-html-radio-buttons)
            (local-set-key [(control o) (l)] 'exal-html-link)
            (local-set-key [(control o) (i)] 'exal-html-image)))

;; todoo
(autoload 'todoo "todoo" "TODO Mode" t)
(add-to-list 'auto-mode-alist '("TODO$" . todoo-mode))

;; always end a file with a newline
(setq require-final-newline 't)

(defun totd ()
 (with-output-to-temp-buffer "*Tip of the day*"
   (let* ((commands (loop for s being the symbols
                          when (commandp s) collect s))
          (command (nth (random (length commands)) commands)))
      (concat "Your tip for the day is:\n"
              (describe-function command)
              "\n\nInvoke with:\n\n"
                (where-is command t)

;;;; Time-stamp ;;;;

(setq time-stamp-active t
      time-stamp-warn-inactive t
;     time-stamp-format "%:y-%02m-%02d %02H:%02M:%02S %u" ; default
      time-stamp-format "%3a %02d-%3b-%:y %02H:%02M:%02S %u on %s")

;; Auto update timestamp in stamped files.
  (add-hook (if (boundp 'before-save-hook) 'before-save-hook
              'write-file-hooks) 'time-stamp)

;; disabling scratch saving 
(add-hook 'emacs-startup-hook
          (lambda ()
            (let ((buffer (get-buffer "*scratch*")))
              (when buffer
                (with-current-buffer buffer
                  (setq buffer-offer-save nil)
                  (auto-save-mode -1))))))

(put 'working-mode-line-message 'risky-local-variable nil)

;; goto-matching-paren

(defun exal-goto-matching-paren ()
  "If point is sitting on a parenthetic character, jump to its match."
  (cond ((looking-at "\\s\(") (forward-list 1))
           (backward-char 1)
           (looking-at "\\s\)")) (forward-char 1) (backward-list 1))))

;; keybindings
(global-set-key [(control q)] 'exal-goto-matching-paren)
;; this for avoid conflicts with cua-mode
(global-set-key [(control d)] 'scroll-up)
(global-set-key [(control f)] 'scroll-down)

(let ((menu '("Exal"
              ["Read mail" gnus]
              ["Read mail offline" gnus-unplugged]
              ["Goto Matching Paren" exal-goto-matching-paren]
              ("Gnus stuff"
               ["Insert importance High" message-insert-importance-high]
               ["Insert Cc header" message-goto-cc]
               ["Insert importance low" message-insert-importance-low])
               ["Buffer" htmlize-buffer]
               ["File" htmlize-file])
               ["Document" exal-latex-document-skeleton]
               ["Figure" exal-latex-figure-skeleton]
               ["Table" exal-latex-table-skeleton]
               ["Listing" exal-latex-listing-skeleton])
               ["Tip Of The Day" totd]
               ["Print buffer" print-buffer])))
  (if (fboundp 'add-submenu)
      (add-submenu nil menu)
    (easy-menu-define exal-menu global-map "Exal's Personal Menu" menu)
    (easy-menu-add exal-menu global-map)))

;;; This code only works for my Emacs 21.4.1

 ((string-equal (number-to-string 21) (substring (emacs-version) 10 12))
  ;; evaluate version 21 code


;; For common lisp programming with emacs-slime
(setq inferior-lisp-program "/usr/bin/clisp")
(require 'slime)

;; navigation

(add-hook 'dired-load-hook
           (lambda () (require 'dired-explore)))


;;;                          ;;;
;;;  Muse config             ;;;

;; muse modes

(require 'muse-mode)     
(require 'muse-colors)
(require 'muse-html)     
(require 'muse-latex)
(require 'muse-texinfo)
(require 'muse-docbook)

;; muse project

(require 'muse-project)

(setq muse-project-alist
         ("/home/exal/test" :default "index")
         (:base "html" :path "/home/exal/web")
         (:base "pdf" :path "/home/exal/web/pdf"))))

)) ;; end emacs 21.4 codes

;;;  This code works only with my Emacs 23

((string-equal (number-to-string 23) (substring (emacs-version) 10 12))
  ;; evaluate version 23 code

;; abbrevs

(setq abbrev-file-name            
        (expand-file-name "abbrevs" exal-emacs-dir))

(setq save-abbrevs 'silently)           
(setq default-abbrev-mode t)

;; some alias

(defalias 'eb 'exal-eval-buffer)
(defalias 'mp 'muse-publish-this-file)
(defalias 'email 'exal-email)
(defalias 'tdoe 'toggle-debug-on-error)

(defun exal-email (&optional arg dont-connect slave)
  (interactive "P")
  (require 'gnus)
  (gnus-1 arg dont-connect slave))

;; Smileys

(setq smiley-regexp-alist
  '(("\\(;-?)\\)\\W"                1 "blink")
    ("\\(:-]\\)\\W"                 1 "forced")
    ("\\(8-)\\)\\W"                 1 "braindamaged")
    ("\\(:-|\\)\\W"                 1 "indifferent")
    ("\\(:-[/\\]\\)\\W"             1 "wry")
   ; ("\\(:[/\\]\\)\\W"             1 "wry")
    ("\\(:-(\\)\\W"                 1 "sad")
    ("\\(X-)\\)\\W"                 1 "dead")
    ("\\(:-{\\)\\W"                 1 "frown")
    ("\\(>:-)\\)\\W"                1 "evil")
    ("\\(;-(\\)\\W"                 1 "cry")
    ("\\(:-D\\)\\W"                 1 "grin")
    ("\\(:-p\\)\\W"                 1 "tongue")
    ("\\(:p\\)\\W"                  1 "tongue")
    ("\\(:O\\)\\W"                  1 "omg")
    ("\\(:-O\\)\\W"                 1 "omg")
    ("\\(:-\\$\\)\\W"               1 "embarrased")
    ("\\(:\\$\\)\\W"                1 "embarrased")
    ("\\(:S\\)\\W"                  1 "confused")
    ("\\(\\^?:-?)\\)\\W"            1 "smile")
    ("\\(:-*[<?]+\\)\\W"            1 "FaceAngry")
    ("\\(:-+\\]+\\)\\W"             1 "FaceGoofy")
    ("\\(:-*D\\)\\W"                1 "FaceGrinning")
    ("\\(:-*[)>}?]+\\)\\W"          1 "FaceHappy")
    ("\\(=[)?]+\\)\\W"              1 "FaceHappy")
    ("\\(:-*[/\\\"]\\)[^/]\\W"      1 "FaceIronic")
    ("[^.0-9]\\([8|]-*[|Oo%]\\)\\W" 1 "FaceKOed")
    ("\\([:|]-*#+\\)\\W"            1 "FaceNyah")
    ("\\(:-*[({]+\\)\\W"            1 "FaceSad")
    ("\\(=[({]+\\)\\W"              1 "FaceSad")
    ("\\(:-*[Oo\*]\\)\\W"           1 "FaceStartled")
    ("\\(:-*|\\)\\W"                1 "FaceStraight")
    ("\\(:-*p\\)\\W"                1 "FaceTalking")
    ("\\(:-*d\\)\\W"                1 "FaceTasty")
    ("\\(;-*[>)}?]+\\)\\W"          1 "FaceWinking")
    ("\\(:-*[Vv?]\\)\\W"            1 "FaceWry")
    ("\\([:|]-*P\\)\\W"             1 "FaceYukky")))

    (defun caf-browse-url-in-konqueror-new-tab (url &rest ARGS)
      "Open URL in a new Konqueror tab"
       (browse-url-interactive-arg "URL: "))
      (call-process "sh" nil t nil "-c" (concat "~/scripts/ " url)))

    (setq browse-url-browser-function 'caf-browse-url-in-konqueror-new-tab)

;;; Emms configs
(require 'earcon)
(require 'emms-info-mp3info) 
(require 'emms)
(require 'emms-mode-line-icon)
(require 'emms-info-ogg)
(require 'emms-player-mpd)
;(require 'emms-default)
(require 'emms-player-mplayer)
(require 'emms-playlist-mode)

;(emms-setup 'tiny "~/musica")

(setq emms-player-list '(emms-player-mpg321

(setq emms-mode-line-titlebar-function 'emms-mode-line-playlist-current)

(defun exal-emms-current ()
  (emms-track-description (emms-playlist-current-selected-track)))

          ;; Show the current track each time EMMS
          ;; starts to play a track with "NP : "
        (add-hook 'emms-player-started-hook 'emms-show)
        (setq emms-show-format "NP: %s")
          ;; When asked for emms-play-directory,
          ;; always start from this directory        
       (setq emms-source-file-default-directory "~/musica/")
          ;; Want to use alsa with mpg321 ? 
        (setq emms-player-mpg321-parameters '("-o" "alsa"))

(defun emms-google-for-lyrics ()
   (concat ""
           (replace-regexp-in-string " +" "+"
                                     (concat "lyrics "
                                             (delete ?- (emms-track-description

(setq emms-playlist-buffer-name "*EMMS Playlist*"
      emms-playlist-mode-open-playlists t)

;; Icon setup.
(setq emms-mode-line-icon-before-format "["
      emms-mode-line-format " %s]"
      emms-mode-line-icon-color "lightgrey")

;;; erc-speak configurations

;; load erc-speak
;(require 'erc-speak)
;(defvar emacspeak-default-sound
;  (expand-file-name
;   "default-8k/"
;   emacspeak-sounds-directory)
;  "Default sound to play if requested icon not found.")

;(when (featurep 'emacspeak)
;   (require 'emacspeak-aumix)
;   (setq emacspeak-auditory-icon-function 'emascpeak-play-auditory-icon)

;   (setq emacspeak-aumix-multichannel-capable-p t)
;   (emacspeak-toggle-auditory-icons 1))

;; ERC

(setq erc-startup-file-list

(when (featurep 'erc)
  (require 'exal-erc))

(defun exal-irc (y-or-n)
  "Connect to IRC."
   (require 'exal-erc)
   (interactive (list (y-or-n-p "IRC? ")))
   (if (eq y-or-n t)
       (erc :server "" 
            :port 6667
            :nick (capitalize (user-login-name))
            :full-name (concat (user-full-name) " -"))
     (message "bye bye.."))
   (add-hook 'erc-after-connect 'exal-irc-passwd-aut)
   (add-hook 'erc-text-matched-hook 'exal-match-irc-nick))

(defalias 'eirc 'exal-irc)

; bitlbee

(defun exal-msg (y-or-n)
  "Connect to bitlbee."
  (setq erc-hide-list '("MODE"))
  (interactive (list (y-or-n-p "mensajeria? ")))
 (if (eq y-or-n t)
         (erc   :server "localhost" 
                :port 6666
                :nick "Exal" )
   (message "bye bye.."))
 (add-hook 'erc-join-hook 'exal-bitlbee-identify)
 (add-hook 'erc-join-hook 'erc-nicklist)
 (add-hook 'erc-join-hook 
           '(lambda (&rest ignore) 
              (add-hook 'erc-insert-pre-hook 'exal-erc-match-irc-nick-sound)
              (add-hook 'erc-send-pre-hook 'exal-erc-match-irc-nick-sound)))
(add-hook 'erc-server-PRIVMSG-functions '(lambda (&rest ignore)
                                             (expand-file-name "bing.wav" exal-emacs-dir)))))

; (add-hook 'erc-insert-post-hook 
;          (lambda () 
;            (goto-char (point-min)) 
;            (when (re-search-forward
               ;;;          (regexp-quote  (erc-current-nick)) nil t) 
               ;;; (play-sound-file 
               ;;;      (expand-file-name "bing.wav" exal-emacs-dir)))

 (defalias 'msn 'exal-msg)

(setq gnus-init-file 
      (expand-file-name "exal-gnus.el" exal-emacs-dir))

(message "==> emacs.el successfully loaded. <==")

))) ;; end emacs 23 codes

;;; Local Variables:
;;; mode: emacs-lisp
;;; comment-column: 0
;;; comment-start: ";;; "
;;; paragraph-separate: "[  ^L]*$"
;;; End:
;;; emacs.el ends here