1 ;; Copyright (C) 2007 Vesa Karvonen
3 ;; MLton is released under a BSD-style license.
4 ;; See the file MLton-LICENSE for details.
6 (require 'def-use-util
)
8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9 ;; Points and Positions
11 (defun def-use-pos-to-point (pos)
12 "Returns the value of point in the current buffer at the position."
14 (def-use-goto-line (def-use-pos-line pos
))
15 (+ (point) (def-use-pos-col pos
))))
17 (defun def-use-point-to-pos (point)
18 "Returns the position corresponding to the specified point in the
23 (let ((line (+ (count-lines 1 (point)) 1))
24 (col (- point
(point))))
25 (def-use-pos line col
))))
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;; Basic symbol lookup support
30 (defvar def-use-mode-to-move-to-symbol-start-alist nil
31 "Association list mapping modes to functions that move the point
32 backwards to the start of the symbol at the point.")
34 (defvar def-use-mode-to-move-to-symbol-end-alist nil
35 "Association list mapping modes to functions that move the point to the
36 end of the symbol at the point.")
38 (defun def-use-move-to-symbol-start ()
40 (assoc major-mode def-use-mode-to-move-to-symbol-start-alist
)))
42 (funcall (cdr mode-move
))
43 (skip-syntax-backward "w_" (def-use-point-at-current-line)))))
45 (defun def-use-move-to-symbol-end ()
47 (assoc major-mode def-use-mode-to-move-to-symbol-end-alist
)))
49 (funcall (cdr mode-move
))
50 (skip-syntax-forward "w_" (def-use-point-at-next-line)))))
52 (defun def-use-ref-at-point (point)
53 "Returns a reference for the symbol at the specified point in the
55 (let ((src (def-use-buffer-file-truename)))
61 (def-use-move-to-symbol-start)
64 (defun def-use-extract-sym-name-at-point (point)
65 "Tries to extracts what looks like the name of the symbol at point.
66 This doesn't really understand the syntax of the language, so the result
67 is only valid when there really is a symbol at the point."
70 (let* ((start (progn (def-use-move-to-symbol-start) (point)))
71 (end (progn (def-use-move-to-symbol-end) (point))))
72 (when (and (<= start point
)
75 (buffer-substring start end
)))))
77 (defun def-use-extract-sym-name-at-ref (ref)
78 "Tries to extract what looks like the name of the symbol at ref."
79 (save-window-excursion
80 (def-use-find-file (def-use-ref-src ref
))
81 (def-use-extract-sym-name-at-point
82 (def-use-pos-to-point (def-use-ref-pos ref
)))))
84 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
86 (provide 'def-use-sym
)