在给定行号和列号的文件中计算偏移量

时间:2014-05-11 01:13:58

标签: emacs elisp

elisp中是否有内置函数给出文件名,行号和列号会将字符偏移量返回到文件中?

1 个答案:

答案 0 :(得分:1)

内置?从来没听说过。这是你想要的吗?

(defun foo (file line column &optional msgp)
  "..."
  (interactive (list (read-file-name "File: ") 
                     (read-number    "Line: ")
                     (read-number    "Columnn: ")
                     t))
  (with-current-buffer (find-file-noselect file)
    (goto-line line)
    (forward-char column)
    (when msgp (message "Char in file: %d" (point)))
    (point)))

这并不需要处理所选行上是否有足够的行或列,但你可以处理它。