 	 (ro    (gethash-nil r tys)))
     (gethash-nil "ann" (gethash-nil c ro))))
 
-;; -- Display --------------------------------------------------------------
-
-;; If you want the separate balloon-popup
-(defun liquid-tip-popup (text)
-  "Display text in a window popup"
+;; ------------------------------------------------------------------------
+;; Display Annot in Tooltip 
+;; ------------------------------------------------------------------------
+
+;; For simple, ascii popups, use:
+;;    (setq liquid-tip-mode 'ascii) 
+;;
+;; For emacs', balloon based popups, use:
+;;    (setq liquid-tip-mode 'balloon)
+
+(defvar liquid-tip-mode 'balloon)
+
+(defun pad-line (str)
+  (concat " " str " "))
+
+(defun popup-tip-pad (text)
+  (let* ((lines     (split-string text "\n"))
+         (pad-lines (mapcar 'pad-line lines))
+	 (pad-text  (concat "\n" (mapconcat 'identity pad-lines "\n") "\n")))
+    (popup-tip pad-text)))
+
+(defun liquid-tip-popup-balloon (text)
+  "Display text in a balloon popup"
   (if (and (functionp 'ac-quick-help-use-pos-tip-p)
            (ac-quick-help-use-pos-tip-p))
       (pos-tip-show text 'popup-tip-face nil nil 300 popup-tip-max-width)
-    (popup-tip text)))
-
-;; If you just want the ascii-popup
-;; (defun liquid-tip-popup (text)
-;;  "Display text in ascii popup"
-;;   (popup-tip text))
-
+    (popup-tip-pad text)))
+
+(defun liquid-tip-popup-ascii (text)
+ "Display text in ascii popup"
+  (popup-tip-pad text))
+
+(defun liquid-tip-popup (text)
+  (if (equal liquid-tip-mode 'ascii)
+      (liquid-tip-popup-ascii   text)
+      (liquid-tip-popup-balloon text)))
 
 ;; -- Compute range ---------------------------------------------------------
 

;;; Code:
(eval-when-compile (require 'cl))
(require 'auto-complete)
(require 'json-mode)
(require 'json)
(require 'ring)
(require 'etags)
;; (require 'flymake)
;; (require 'eldoc)
(require 'pos-tip nil t)
;; (require 'log4e)
;; (require 'yaxception)
(require 'thingatpt)
(require 'button-lock)



(cl-defstruct position file row col)

(defun get-string-from-file (filePath)
  "Return filePath's file content."


(defun get-json-from-file (filePath)
  "Return json object from filePath's content"
  (if (file-exists-p filePath)
      (let* ((json-key-type 'string)
	     (str (get-string-from-file filePath)))
	(json-read-from-string str))
      nil))

;; ------------------------------------------------------------------------
;; get/set annot information 
;; ------------------------------------------------------------------------

(defun gethash-nil (key table) 
  (if table 
      (gethash key table nil)
      nil))

(defun liquid-annot-filepath-prefix (mode)
  "Return prefix of annotation file using mode"
  (if (equal mode 'flycheck)
      "flycheck_"
      nil))

;; (liquid-annot 'flycheck "/path/to/file.hs") 
;;    ==> "/path/to/.liquid/flycheck_file.hs.json"
;;
;; (liquid-annot nil       "/path/to/file.hs") 
;;    ==> "/path/to/.liquid/file.hs.json"

(defun liquid-annot-filepath (mode file)
  "Return name of annotation file"
  (let* ((dir    (file-name-directory file))
	 (name   (file-name-nondirectory file))
	 (prefix (liquid-annot-filepath-prefix mode)))
    (concat dir ".liquid/" prefix name ".json")))

(defvar liquid-annot-table (make-hash-table :test 'equal))

;; API
(defun liquid-annot-set (file mode)
  "Load information for file into liquid-annot-table"
  (let* ((file-path        (liquid-annot-filepath mode file))
	 (json-object-type 'hash-table)
	 (file-info        (get-json-from-file file-path)))
    (if file-info (puthash file file-info liquid-annot-table))))

;; API
(defun liquid-annot-get (file row col)
  "Get annotation for identifier at row, col in file"
  (let* ((table (gethash-nil file liquid-annot-table))
