<commit_before>;;; merlin-imenu.el --- Merlin and imenu integration.   -*- coding: utf-8 -*-
;; Licensed under the MIT license.

;; Author: <NAME> <<EMAIL>>
;; Created: 10 July 2016
;; Version: 0.1
;; Keywords: ocaml, imenu, merlin
;; URL:

(require 'imenu)
(require 'tuareg)
(require 'subr-x)

;;; enable depth and size threshold for OCaml modules with big size
(setq max-lisp-eval-depth 10000)
(setq max-specpdl-size 10000)

;;;
;;; For debugging purpose
;;;
;; (defun merlin-imenu--print-item (item)
;;   (cl-labels ((visit (xs)
;;                      (cond ((null xs) "")
;;                            ((null (cdr xs)) (car (car xs)))
;;                            (t (concat (visit (cdr xs)) " / " (car (car xs)))))))
;;     (if (null item) "" (visit item))))

;;;
;;; For debugging purpose
;;;
;; (defun merlin-imenu--print-all-values (items)
;;   (cl-labels ((visit (xs)
;;                   (when (not (null xs))
;;                     (message (concat "Value: " (car (car xs))))
;;                     (visit (cdr xs))
;;                     )))
;;     (visit items)))

;;;
;;; For debugging purpose
;;;
;; (defun merlin-imenu--print-all-modules (items)
;;   (cl-labels ((visit (xs)
;;                   (when (not (null xs))
;;                     (message (concat "Module: " (car (car xs))))
;;                     (visit (cdr xs))
;;                     )))
;;     (visit items)))

(defun merlin-imenu--list-to-string (items)
  (cl-labels ((visit (xs)
                     (cond ((null xs) "")
                           ((null (cdr xs)) (car xs))
                           (t (concat (visit (cdr xs)) " / " (car xs))))))
    (if (null items) "" (visit items))))

;; go to the location of the item
(defun merlin-imenu--goto-item (line col item)
  (save-excursion
    ;; go to line
    (goto-char (point-min))
    (forward-line (- line 1))
    ;; go to column
    (move-to-column col)
    ;; go to the beginning position of the item
    (search-forward item)
    (search-backward item)
    ;; return the marker
    (point)))

;; the main indexing function
(defun merlin-imenu-create-index ()
  "Set imenu function"
  (merlin/sync)
  (let* ((pos (merlin/unmake-point (point)))
         (outline (merlin/send-command `outline)))
    (when outline
      ;; (message outline)
      (let ((module-list) (value-list) (type-list)
            (class-list) (exception-list) (constructor-list)
            (label-list) (misc-list))
        (cl-labels
            ((visit-one (prefix x)
                        (let* ((fstart (nth 1 x))
                               (fname (nth 3 x))
                               (fkind (nth 4 x))
                               (start-line (cdr (nth 2 fstart)))
                               (start-col (cdr (nth 3 fstart)))
                               (name (cdr fname))
                               (kind (cdr fkind))
                               (children (nth 5 x))
                               (item (merlin-imenu--list-to-string
                                      (cons name prefix))))
                          (progn
                            (setq marker (make-marker))
                            (setq start-pos
                                  (merlin-imenu--goto-item start-line
                                                           start-col<commit_msg>merlin-imenu: add missing free variables<commit_after>;;; merlin-imenu.el --- Merlin and imenu integration.   -*- coding: utf-8 -*-
;; Licensed under the MIT license.

;; Author: <NAME> <<EMAIL>>
;; Created: 10 July 2016
;; Version: 0.1
;; Keywords: ocaml, imenu, merlin
;; URL:

(require 'imenu)
(require 'tuareg)
(require 'subr-x)
(require 'merlin)

;;; enable depth and size threshold for OCaml modules with big size
(setq max-lisp-eval-depth 10000)
(setq max-specpdl-size 10000)

;;;
;;; For debugging purpose
;;;
;; (defun merlin-imenu--print-item (item)
;;   (cl-labels ((visit (xs)
;;                      (cond ((null xs) "")
;;                            ((null (cdr xs)) (car (car xs)))
;;                            (t (concat (visit (cdr xs)) " / " (car (car xs)))))))
;;     (if (null item) "" (visit item))))

;;;
;;; For debugging purpose
;;;
;; (defun merlin-imenu--print-all-values (items)
;;   (cl-labels ((visit (xs)
;;                   (when (not (null xs))
;;                     (message (concat "Value: " (car (car xs))))
;;                     (visit (cdr xs))
;;                     )))
;;     (visit items)))

;;;
;;; For debugging purpose
;;;
;; (defun merlin-imenu--print-all-modules (items)
;;   (cl-labels ((visit (xs)
;;                   (when (not (null xs))
;;                     (message (concat "Module: " (car (car xs))))
;;                     (visit (cdr xs))
;;                     )))
;;     (visit items)))

(defun merlin-imenu--list-to-string (items)
  (cl-labels ((visit (xs)
                     (cond ((null xs) "")
                           ((null (cdr xs)) (car xs))
                           (t (concat (visit (cdr xs)) " / " (car xs))))))
    (if (null items) "" (visit items))))

;; go to the location of the item
(defun merlin-imenu--goto-item (line col item)
  (save-excursion
    ;; go to line
    (goto-char (point-min))
    (forward-line (- line 1))
    ;; go to column
    (move-to-column col)
    ;; go to the beginning position of the item
    (search-forward item)
    (search-backward item)
    ;; return the marker
    (point)))

;; the main indexing function
(defun merlin-imenu-create-index ()
  "Set imenu function"
  (merlin/sync)
  (let* ((pos (merlin/unmake-point (point)))
         (outline (merlin/send-command `outline)))
    (when outline
      ;; (message outline)
      (let ((module-list) (value-list) (type-list)
            (class-list) (exception-list) (constructor-list)
            (label-list) (misc-list)
            (marker) (start-pos) (fitem))
        (cl-labels
            ((visit-one (prefix x)
                        (let* ((fstart (nth 1 x))
                               (fname (nth 3 x))
                               (fkind (nth 4 x))
                               (start-line (cdr (nth 2 fstart)))
                               (start-col (cdr (nth 3 fstart)))
                               (name (cdr fname))
                               (kind (cdr fkind))
                               (children (nth 5 x))
                               (item (merlin-imenu--list-to-string
                                      (cons name prefix))))
                          (progn
                            (setq marker (make-marker))
                            (setq start-pos
                                  (merlin-imenu--goto-item start-line
                                                           start-col
{'fraction_non_alphanumeric': 0.15455354494215368, 'fraction_numerical': 0.0077128448531593, 'mean_word_length': 1.4360549132947977, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3060179', 'n_tokens_mistral': 2111, 'n_tokens_neox': 1988, 'n_words': 564}