[MLton-commit] r5151

Vesa Karvonen vesak at mlton.org
Thu Feb 8 04:44:33 PST 2007


Don't report symbol info if buffer has been modified or the symbol name at
the cursor doesn't match.

----------------------------------------------------------------------

U   mlton/trunk/ide/emacs/def-use-mode.el
U   mlton/trunk/ide/emacs/def-use-util.el
U   mlton/trunk/ide/emacs/esml-du-mlton.el

----------------------------------------------------------------------

Modified: mlton/trunk/ide/emacs/def-use-mode.el
===================================================================
--- mlton/trunk/ide/emacs/def-use-mode.el	2007-02-08 10:03:44 UTC (rev 5150)
+++ mlton/trunk/ide/emacs/def-use-mode.el	2007-02-08 12:44:31 UTC (rev 5151)
@@ -7,7 +7,6 @@
 ;; uses.  See http://mlton.org/EmacsDefUseMode for further information.
 
 ;; XXX mode specific on-off switching
-;; XXX disable def-use when file is modified
 ;; XXX rename-variable
 
 (require 'def-use-data)
@@ -99,10 +98,28 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; High-level symbol lookup
 
-(defvar def-use-mode-to-move-to-symbol-beginning-alist nil
+(defvar def-use-mode-to-move-to-symbol-start-alist nil
   "Association list mapping modes to functions that move the point
-(backwards) to the beginning of the symbol at the point.")
+backwards to the start of the symbol at the point.")
 
+(defvar def-use-mode-to-move-to-symbol-end-alist nil
+  "Association list mapping modes to functions that move the point to the
+end of the symbol at the point.")
+
+(defun def-use-move-to-symbol-start ()
+  (let ((mode-move
+         (assoc major-mode def-use-mode-to-move-to-symbol-start-alist)))
+    (if mode-move
+        (funcall (cdr mode-move))
+      (skip-syntax-backward "w_" (def-use-point-at-current-line)))))
+
+(defun def-use-move-to-symbol-end ()
+  (let ((mode-move
+         (assoc major-mode def-use-mode-to-move-to-symbol-end-alist)))
+    (if mode-move
+        (funcall (cdr mode-move))
+      (skip-syntax-forward "w_" (def-use-point-at-next-line)))))
+
 (defun def-use-ref-at-point (point)
   "Returns a reference for the symbol at the specified point in the
 current buffer."
@@ -112,21 +129,28 @@
         (def-use-point-to-pos
           (save-excursion
             (goto-char point)
-            (let ((mode-move
-                   (assoc
-                    major-mode
-                    def-use-mode-to-move-to-symbol-beginning-alist)))
-              (if mode-move
-                  (funcall (cdr mode-move))
-                (skip-syntax-backward "w_" (def-use-point-at-current-line))))
+            (def-use-move-to-symbol-start)
             (point)))))))
 
+(defun def-use-extract-sym-name-at-point (point)
+  "Extracts what looks like the name of the symbol at point.  This doesn't
+really understand the syntax of the language, so the result is only valid
+when there really is a symbol at the point."
+  (save-excursion
+    (goto-char point)
+    (let* ((start (progn (def-use-move-to-symbol-start) (point)))
+           (end (progn (def-use-move-to-symbol-end) (point))))
+      (buffer-substring start end))))
+
 (defun def-use-sym-at-point (point)
   "Returns symbol information for the symbol at the specified point."
-  ;; XXX If data unvailable for current buffer then attempt to load it.
   (let ((ref (def-use-ref-at-point point)))
     (when ref
-      (def-use-sym-at-ref ref))))
+      (let ((sym (def-use-sym-at-ref ref)))
+        (when (and sym
+                   (string= (def-use-sym-name sym)
+                            (def-use-extract-sym-name-at-point point)))
+          sym)))))
 
 (defun def-use-current-sym ()
   "Returns symbol information for the symbol at the current point."

Modified: mlton/trunk/ide/emacs/def-use-util.el
===================================================================
--- mlton/trunk/ide/emacs/def-use-util.el	2007-02-08 10:03:44 UTC (rev 5150)
+++ mlton/trunk/ide/emacs/def-use-util.el	2007-02-08 12:44:31 UTC (rev 5151)
@@ -28,22 +28,26 @@
     (when name
       (def-use-file-truename name))))
 
+(defun def-use-find-buffer-visiting-file (file)
+  "Tries to find a buffer visiting the specified file."
+  (let ((truename (def-use-file-truename file)))
+    (loop for buffer in (buffer-list) do
+      (if (with-current-buffer buffer
+            (string= buffer-file-truename truename))
+          (return buffer)))))
+
 (defun def-use-find-file (file &optional other-window)
   "Roughly as `find-file' or `find-file-other-window' except that will not
 open the file a second time if a buffer is editing a file by the same true
 file name."
-  (let* ((truename (def-use-file-truename file))
-         (buffer (loop for buffer in (buffer-list) do
-                   (if (with-current-buffer buffer
-                         (string= buffer-file-truename truename))
-                       (return buffer)))))
+  (let ((buffer (def-use-find-buffer-visiting-file file)))
     (if buffer
         (if other-window
             (switch-to-buffer-other-window buffer)
           (switch-to-buffer buffer))
       (if other-window
-          (find-file-other-window truename)
-        (find-file truename)))))
+          (find-file-other-window file)
+        (find-file file)))))
 
 (defun def-use-point-at-next-line ()
   "Returns point at the beginning of the next line."

Modified: mlton/trunk/ide/emacs/esml-du-mlton.el
===================================================================
--- mlton/trunk/ide/emacs/esml-du-mlton.el	2007-02-08 10:03:44 UTC (rev 5150)
+++ mlton/trunk/ide/emacs/esml-du-mlton.el	2007-02-08 12:44:31 UTC (rev 5151)
@@ -26,15 +26,24 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Move to symbol
 
-(defun esml-du-move-to-symbol-beginning ()
-  "Moves to the beginning of the SML symbol at point."
+(defun esml-du-move-to-symbol-start ()
+  "Moves to the start of the SML symbol at point."
   (let ((limit (def-use-point-at-current-line)))
     (when (zerop (skip-chars-backward "a-zA-Z0-9_'" limit))
       (skip-chars-backward "-!%&$#+/:<=>?@~`^|*\\" limit))))
 
-(add-to-list 'def-use-mode-to-move-to-symbol-beginning-alist
-             (cons 'sml-mode (function esml-du-move-to-symbol-beginning)))
+(add-to-list 'def-use-mode-to-move-to-symbol-start-alist
+             (cons 'sml-mode (function esml-du-move-to-symbol-start)))
 
+(defun esml-du-move-to-symbol-end ()
+  "Moves to the end of the SML symbol at point."
+  (let ((limit (def-use-point-at-next-line)))
+    (when (zerop (skip-chars-forward "a-zA-Z0-9_'" limit))
+      (skip-chars-forward "-!%&$#+/:<=>?@~`^|*\\" limit))))
+
+(add-to-list 'def-use-mode-to-move-to-symbol-end-alist
+             (cons 'sml-mode (function esml-du-move-to-symbol-end)))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Methods
 
@@ -58,7 +67,10 @@
         (file-attributes (def-use-ref-src ref))
         (esml-du-ctx-attr ctx))
       (esml-du-reparse ctx)
-    (gethash ref (esml-du-ctx-ref-to-sym-table ctx))))
+    (unless (let ((buffer (def-use-find-buffer-visiting-file
+                            (def-use-ref-src ref))))
+              (and buffer (buffer-modified-p buffer)))
+      (gethash ref (esml-du-ctx-ref-to-sym-table ctx)))))
 
 (defun esml-du-sym-to-uses (sym ctx)
   (if (def-use-attr-newer?




More information about the MLton-commit mailing list