From 78e9854baefd74c53b47aae476a5e2120f90b760 Mon Sep 17 00:00:00 2001 From: Soonho Kong Date: Tue, 7 Oct 2014 14:40:54 -0700 Subject: [PATCH] fix(emacs): support tabs in a file Fix #226 --- src/emacs/lean-company.el | 3 +-- src/emacs/lean-info.el | 4 ++-- src/emacs/lean-server.el | 2 +- src/emacs/lean-util.el | 11 +++++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/emacs/lean-company.el b/src/emacs/lean-company.el index 4d490ba30..d435e5b23 100644 --- a/src/emacs/lean-company.el +++ b/src/emacs/lean-company.el @@ -126,7 +126,7 @@ (defun company-lean--findg-candidates (prefix) (let ((line-number (line-number-at-pos)) - (column-number (current-column)) + (column-number (lean-line-offset)) pattern) (lean-server-send-cmd-sync (lean-cmd-wait) '(lambda () ())) (setq pattern (if current-prefix-arg @@ -203,7 +203,6 @@ triggers a completion immediately." (defun company-lean--findp-candidates (prefix) (let ((line-number (line-number-at-pos)) - (column-number (current-column)) pattern) (lean-server-send-cmd-sync (lean-cmd-wait) '(lambda () ())) (lean-server-send-cmd-sync (lean-cmd-findp line-number prefix) diff --git a/src/emacs/lean-info.el b/src/emacs/lean-info.el index bf83fa112..9565c796f 100644 --- a/src/emacs/lean-info.el +++ b/src/emacs/lean-info.el @@ -456,13 +456,13 @@ Take out \"BEGININFO\" and \"ENDINFO\" and Use \"ACK\" as a delim." (save-excursion (forward-char 1) (backward-list 1) - `(,(line-number-at-pos) . ,(current-column)))) + `(,(line-number-at-pos) . ,(lean-line-offset)))) (defun lean-get-info-record-at-point (cont) "Get info-record at the current point" (let* ((file-name (buffer-file-name)) (line-number (line-number-at-pos)) - (column-number (current-column)) + (column-number (lean-line-offset)) (cmd (cond ((looking-at "(") (lean-cmd-info line-number column-number)) ;; TODO(soonhok): give information on '(' diff --git a/src/emacs/lean-server.el b/src/emacs/lean-server.el index ae992b5e5..1d74e60bf 100644 --- a/src/emacs/lean-server.el +++ b/src/emacs/lean-server.el @@ -480,7 +480,7 @@ If it's not the same with file-name (default: buffer-file-name), send VISIT cmd. (defun lean-server-get-info-record-at-pos (body) (let* ((file-name (buffer-file-name)) - (column (current-column))) + (column (lean-line-offset))) (when (and (or (looking-at (rx (or white "," ")" "}" "]"))) (eolp)) (> column 1)) diff --git a/src/emacs/lean-util.el b/src/emacs/lean-util.el index 5730aefbd..271fa93fc 100644 --- a/src/emacs/lean-util.el +++ b/src/emacs/lean-util.el @@ -166,4 +166,15 @@ (when id-beg (buffer-substring id-beg cur-pos)))))) +(defun lean-line-offset () + "Return the byte-offset of current position, counting from the + beginning of the line" + (interactive) + (let ((bol-pos + (save-excursion + (beginning-of-line) + (point))) + (pos (point))) + (- pos bol-pos))) + (provide 'lean-util)