 ;;;;;;;;;;
 ;; HELM ;;
 ;;;;;;;;;;
+
+(require 'helm-grepint)
+
+(defun helm-ido-like-activate-helm-modes () 
+  (require 'helm-config) 
+  (helm-mode 1) 
+  (helm-flx-mode 1) 
+  (helm-fuzzier-mode 1))
+
+(defun helm-ido-like-load-ido-like-bottom-buffer ()
+  ;; popup helm-buffer at the bottom
+  (setq helm-split-window-in-side-p t) 
+  (add-to-list 'display-buffer-alist '("\\`\\*helm.*\\*\\'" (display-buffer-in-side-window) 
+                                       (window-height . 0.4))) 
+  (add-to-list 'display-buffer-alist '("\\`\\*helm help\\*\\'" (display-buffer-pop-up-window)))
+
+  ;; same for helm swoop
+  (setq helm-swoop-split-with-multiple-windows nil helm-swoop-split-direction
+        'split-window-vertically helm-swoop-split-window-function 'helm-default-display-buffer)
+  ;; dont display the header line
+  (setq helm-display-header-line nil)
+  ;; input in header line
+  (setq helm-echo-input-in-header-line t) 
+  (add-hook 'helm-minibuffer-set-up-hook 'helm-hide-minibuffer-maybe))
+
+
+(defvar helm-ido-like-bg-color (face-attribute 'default 
+                                               :background))
+
+(defun helm-ido-like-setup-bg-color-1 () 
+  (with-helm-buffer 
+    (make-local-variable 'face-remapping-alist) 
+    (add-to-list 'face-remapping-alist `(default 
+                                          (:background ,helm-ido-like-bg-color)))))
+
+(defun helm-ido-like-setup-bg-color () 
+  (add-hook 'helm-after-initialize-hook 'helm-ido-like-setup-bg-color-1))
+
+;;;###autoload
+(defun helm-ido-like () 
+  "Configure and activate `helm', `helm-fuzzier' and `helm-flx'." 
+  (interactive) 
+  (helm-ido-like-activate-helm-modes) 
+  (helm-ido-like-load-ido-like-bottom-buffer) 
+  (helm-ido-like-setup-bg-color))
 
 (setq helm-recentf-fuzzy-match 1)
 (setq helm-buffers-fuzzy-matching 1)

;;;;;;;;;;;;;;;;;;;;

;; Go fullscreen on current frame
(defun toggle-fullscreen (&optional f)
  (interactive)
  (let ((current-value (frame-parameter nil 'fullscreen)))
    (set-frame-parameter nil 'fullscreen
      (if (equal 'fullboth current-value)
        (if (boundp 'old-fullscreen) old-fullscreen nil)
        (progn (setq old-fullscreen current-value)
          'fullboth)))))

;; renames a buffer and its underlying file to the specified name
(defun rename-file-and-buffer (new-name)
  "Renames both current buffer and file it's visiting to NEW-NAME."
  (interactive "sNew name: ")
  (let ((name (buffer-name))
        (filename (buffer-file-name)))
    (if (not filename)
        (message "Buffer '%s' is not visiting a file!" name)
      (if (get-buffer new-name)
          (message "A buffer named '%s' already exists!" new-name)
        (progn
          (rename-file name new-name 1)
          (rename-buffer new-name)
          (set-visited-file-name new-name)
          (set-buffer-modified-p nil))))))

;; moves file underlying buffer and updates the buffer path accordingly
(defun move-buffer-file (dir)
 "Moves both current buffer and file it's visiting to DIR." (interactive "DNew directory: ")
 (let* ((name (buffer-name))
         (filename (buffer-file-name))
         (dir
         (if (string-match dir "\\(?:/\\|\\\\)$")
         (substring dir 0 -1) dir))
         (newname (concat dir "/" name)))

 (if (not filename)
        (message "Buffer '%s' is not visiting a file!" name)
 (progn         (copy-file filename newname 1)  (delete-file filename)  (set-visited-file-name newname)         (set-buffer-modified-p nil)     t)))) 

;; function to bind ri ruby inline documentation to a key
(defun ri-bind-key ()
   (local-set-key [f1] 'yari))


(defvar current-date-time-format "%a %b %d %H:%M:%S %Z %Y"
  "Format of date to insert with `insert-current-date-time' func
See help of `format-time-string' for possible replacements")

(defvar current-time-format "%a %H:%M:%S"
  "Format of date to insert with `insert-current-time' func.
Note the weekly scope of the command's precision.")

;; insert current datetime at cursor
(defun insert-current-date-time ()
  "insert the current date and time into current buffer.
Uses `current-date-time-format' for the formatting the date/time."
       (interactive)
;       (insert (let () (comment-start)))
       (insert (format-time-string current-date-time-format (current-time)))
       )

;; insert current time at cursor
(defun insert-current-time ()
  "insert the current time (1-week scope) into the current buffer."
       (interactive)
       (insert (format-time-string current-time-format (current-time)))
       )

(defun copy-buffer-file-name-as-kill (choice)
  "Copy the buffer-file-name to the kill-ring"
  (interactive "cCopy Buffer Name (F) Full, (D) Directory, (N) Name")
  (let ((new-kill-string)
        (name (if (eq major-mode 'dired-mode)
                  (dired-get-filename)
                (or (buffer-file-name) ""))))
    (cond ((eq choice ?f)
           (setq new-kill-string name))
          ((eq choice ?d)
           (setq new-kill-string (file-name-directory name)))
          ((eq choice ?n)
           (setq new-kill-string (file-name-nondirectory name)))
          (t (message "Quit")))
    (when new-kill-string
      (message "%s copied" new-kill-string)
      (kill-new new-kill-string))))


;;  in buffer build system
(setq build-buffer "*ci-shell*")
(setq build-cmd "ant\n")

(defun build-in-buffer ()
  "Send a build command to a running shell"
  (interactive)
  (process-send-string build-buffer build-cmd))

(defun enable-in-buffer-builds (buf cmd)
  (interactive "bSpecify target buffer: \nsSpecify build command to send to buffer %s:")
  (setq build-buffer buf)
  (setq build-cmd cmd)
  (add-hook 'after-save-hook 'build-in-buffer)
  )

(defun disable-in-buffer-builds ()
  (interactive)
  (remove-hook 'after-save-hook 'build-in-buffer)
  )

;; zip/unzip files in dired mode
(eval-after-load "dired-aux"
   '(add-to-list 'dired-compress-file-suffixes
                 '("\\.zip\\'" ".zip" "unzip")))

(eval-after-load "dired"
  '(define-key dired-mode-map "z" 'dired-zip-files))
(defun dired-zip-files (zip-file)
  "Create an archive containing the marked files."
  (interactive "sEnter name of zip file: ")

  ;; create the zip file
  (let ((zip-file (if (string-match ".zip$" zip-file) zip-file (concat zip-file ".zip"))))
    (shell-command
     (concat "zip "
             zip-file
             " "
             (concat-string-list
              (mapcar
               #'(lambda (filename)
                  (file-name-nondirectory filename))
               (dired-get-marked-files))))))

  (revert-buffer)

  ;; remove the mark on all the files  "*" to " "

(setq splash-art "


 ▄▄▄██▀▀▀▓█████▄  █     █░ ░ ██████    ▓█████  ███▄ ▄███▓ ▄▄▄       ▄████▄    ██████
   ▒██   ▒██▀ ██▌▓█░ █ ░█░  ██    ▒    ▓█   ▀ ▓██▒▀█▀ ██▒▒████▄    ▒██▀ ▀█  ▒██    ▒
   ░██   ░██   █▌▒█░ █ ░█    ▓██▄      ▒███   ▓██    ▓██░▒██  ▀█▄  ▒▓█    ▄ ░ ▓██▄
▓██▄██▓  ░▓█▄   ▌░█░ █ ░█    ▒   ██▒   ▒▓█  ▄ ▒██    ▒██ ░██▄▄▄▄██ ▒▓▓▄ ▄██▒  ▒   ██▒
 ▓███▒   ░▒████▓ ░░██▒██▓  ▒██████▒▒   ░▒████▒▒██▒   ░██▒ ▓█   ▓██▒▒ ▓███▀ ░▒██████▒▒
 ▒▓▒▒░    ▒▒▓  ▒ ░ ▓░▒ ▒   ▒ ▒▓▒ ▒ ░   ░░ ▒░ ░░ ▒░   ░  ░ ▒▒   ▓▒█░░ ░▒ ▒  ░▒ ▒▓▒ ▒ ░
 ▒ ░▒░    ░ ▒  ▒   ▒ ░ ░   ░ ░▒  ░ ░    ░ ░  ░░  ░      ░  ▒   ▒▒ ░  ░  ▒   ░ ░▒  ░ ░
 ░ ░ ░    ░ ░  ░   ░   ░   ░  ░  ░        ░   ░      ░     ░   ▒   ░        ░  ░  ░
 ░   ░      ░        ░          ░        ░  ░       ░         ░  ░░ ░            ░
          ░                                                       ░                 ")


