Skip to content

Instantly share code, notes, and snippets.

@zakki
Created January 27, 2013 15:45
Show Gist options
  • Select an option

  • Save zakki/4648916 to your computer and use it in GitHub Desktop.

Select an option

Save zakki/4648916 to your computer and use it in GitHub Desktop.
(defun fix-ocaml-cursor-position (byte-pos)
(let ((len (lambda (p)
(length (encode-coding-string
(buffer-substring 1 p) buffer-file-coding-system)))))
(let* ((pos (/ byte-pos 4))
(b (funcall len pos)))
(while (< b (- byte-pos 1))
(setq pos (+ pos 1))
(setq b (funcall len pos)))
pos)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment