   ;; (dired-mark-files-regexp (filename-to-regexp zip-file))
   )
 
-(defun concat-string-list (list)
-   "Return a string which is a concatenation of all elements of the list separated by spaces"
-   (mapconcat #'(lambda (obj) (format "%s" obj)) list " "))
-
-(defun xml-pretty-region (begin end)
+(defun concat-string-list (list) 
+  "Return a string which is a concatenation of all elements of the list separated by spaces"
+  (mapconcat #'(lambda (obj) 
+                 (format "%s" obj)) list " "))
+
+(defun xml-pretty-region (begin end) 
   "Pretty format XML markup in region. You need to have nxml-mode
 http://www.emacswiki.org/cgi-bin/wiki/NxmlMode installed to do
 this.  The function inserts linebreaks to separate tags that have
 nothing but whitespace between them.  It then indents the markup
-by using nxml's indentation rules."
-  (interactive "r")
-  (save-excursion
-      (nxml-mode)
-      (goto-char begin)
-      (while (search-forward-regexp "\>[ \\t]*\<" nil t)
-        (backward-char) (insert "\n"))
-      (indent-region begin end))
+by using nxml's indentation rules." 
+  (interactive "r") 
+  (save-excursion (nxml-mode) 
+                  (goto-char begin) 
+                  (while (search-forward-regexp "\>[ \\t]*\<" nil t) 
+                    (backward-char) 
+                    (insert "\n")) 
+                  (indent-region begin end)) 
   (message "Ah, much better!"))
 
 
 ;; adjust indents for web-mode to 2 spaces
-(defun my-web-mode-hook ()
+(defun my-web-mode-hook () 
   "Hooks for Web mode. Adjust indents"
-  ;;; http://web-mode.org/
-  (setq web-mode-markup-indent-offset 2)
-  (setq web-mode-css-indent-offset 2)
+;;; http://web-mode.org/
+  (setq web-mode-markup-indent-offset 2) 
+  (setq web-mode-css-indent-offset 2) 
   (setq web-mode-code-indent-offset 2))
 
 
 ;; https://github.com/purcell/exec-path-from-shell
 ;; only need exec-path-from-shell on OSX
 ;; this hopefully sets up path and other vars better
-(defun setup-paths-osx ()
-  (when (memq window-system '(mac ns))
+(defun setup-paths-osx () 
+  (when (memq window-system '(mac ns)) 
     (exec-path-from-shell-initialize)))
 
 ;;; Fix junk characters in shell-mode
-(add-hook 'shell-mode-hook 
-          'ansi-color-for-comint-mode-on)
+(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
 
 ;; Flycheck setup
 ;; disable jshint since we prefer eslint checking
-(setq-default flycheck-disabled-checkers
-              (append flycheck-disabled-checkers
-                      '(javascript-jshint)))
+(setq-default flycheck-disabled-checkers (append flycheck-disabled-checkers '(javascript-jshint)))
 
 ;; use eslint with web-mode for jsx files
 (flycheck-add-mode 'javascript-eslint 'web-mode)

(setq wakatime-cli-path "/usr/local/bin/wakatime")

;; tide
(defun setup-tide-mode ()
  (interactive)
  (tide-setup)
  (flycheck-mode +1)
  (setq flycheck-check-syntax-automatically '(save mode-enabled))
  (eldoc-mode +1)
  (tide-hl-identifier-mode +1)
  (company-mode +1))

;; aligns annotation to the right hand side

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

;; 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 " "
