<commit_before>;;;
;;;; Kawa module support
;;;
;;
;; @created   "Mon Mar 07 13:32:14 EST 2005"
;; @author    "<NAME>"
;; @copyright "NuEcho Inc."
;;


(define-namespace WeakHashMap "class:java.util.WeakHashMap")


;;;
;;;;   Global registry
;;;


(define *module-registry* :: <java.util.WeakHashMap> (WeakHashMap:new))


;;;
;;;; --
;;;; Public interface
;;;


(define (add-to-module-registry! resource modulename)
  (WeakHashMap:put *module-registry* resource modulename))


(define (find-module-name resource)
  (let ((value (WeakHashMap:get *module-registry* resource)))
    (if (eq? value #!null)
        #f
        value)))


(define (symbol->module-name symbol #!optional (buffer (current-buffer)))
  (let* ((dictionary (SchemeEditor:getSymbolDictionary buffer))
         (entries    (array->list (SymbolDictionary:findSymbol dictionary symbol))))
    (and (pair? entries)
         (find-module-name (SymbolEntry:getFile (first entries))))))


(define (add-require-clause #!optional (symbol (symbol-near-point)) (buffer (current-buffer)))
  (let ((modulename (symbol->module-name symbol buffer)))
    (when modulename
      (let* ((insertion (format #f "(require ~A)" modulename)))
        (let-values (((point needs-newline-before) (find-best-require-insertion-point modulename buffer)))
          (when point<commit_msg>Now choose from a list if a symbol is exported by more than one module...<commit_after>;;;
;;;; Kawa module support
;;;
;;
;; @created   "Mon Mar 07 13:32:14 EST 2005"
;; @author    "<NAME>"
;; @copyright "NuEcho Inc."
;;


(define-namespace WeakHashMap "class:java.util.WeakHashMap")


;;;
;;;;   Global registry
;;;


(define *module-registry* :: <java.util.WeakHashMap> (WeakHashMap:new))


;;;
;;;; --
;;;; Public interface
;;;


(define (add-to-module-registry! resource modulename)
  (WeakHashMap:put *module-registry* resource modulename))


(define (find-module-name resource)
  (let ((value (WeakHashMap:get *module-registry* resource)))
    (if (eq? value #!null)
        #f
        value)))


(define (symbol->module-name symbol #!optional (buffer (current-buffer)))
  (let* ((dictionary (SchemeEditor:getSymbolDictionary buffer))
         (entries    (array->list (SymbolDictionary:findSymbol dictionary symbol))))
    (and (pair? entries)
         (choose-from-list
          "Symbol multiply declared"
          "Choose the module to require:"
          (filter symbol? 
                  (map (lambda (entry)
                         (find-module-name (SymbolEntry:getFile entry)))
                       entries))))))


(define (add-require-clause #!optional (symbol (symbol-near-point)) (buffer (current-buffer)))
  (let ((modulename (symbol->module-name symbol buffer)))
    (when modulename
      (let* ((insertion (format #f "(require ~A)" modulename)))
        (let-values (((point needs-newline-before) (find-best-require-insertion-point modulename buffer)))
          (when point
{'fraction_non_alphanumeric': 0.1647901740020471, 'fraction_numerical': 0.008188331627430911, 'mean_word_length': 3.574102964118565, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2682867', 'n_tokens_mistral': 931, 'n_tokens_neox': 870, 'n_words': 227}