@@ -137,14 +137,6 @@ a call to `merlin-occurrences'."
137
137
See `merlin-debug' ."
138
138
:group 'merlin :type 'string )
139
139
140
- (defcustom merlin-polarity-search-buffer-name " *merlin-polarity-search-result*"
141
- " The name of the buffer displaying result of polarity search."
142
- :group 'merlin :type 'string )
143
-
144
- (defcustom merlin-search-by-type-buffer-name " *merlin-search-by-type-result*"
145
- " The name of the buffer displaying result of a search by type query."
146
- :group 'merlin :type 'string )
147
-
148
140
(defcustom merlin-favourite-caml-mode nil
149
141
" The OCaml mode to use for the *merlin-types* buffer."
150
142
:group 'merlin :type 'symbol )
@@ -1098,107 +1090,70 @@ An ocaml atom is any string containing [a-z_0-9A-Z`.]."
1098
1090
(cons (if bounds (car bounds) (point ))
1099
1091
(point ))))
1100
1092
1101
- ; ;;;;;;;;;;;;;;;;;;;;
1102
- ; ; COMMON SEARCH ;;
1103
- ; ;;;;;;;;;;;;;;;;;;;;
1104
1093
1105
- (defun merlin--render-search-result (name type )
1106
- (let ((plain-name (string-remove-prefix " Stdlib__" name)))
1107
- (concat
1108
- (propertize " val " 'face (intern " font-lock-keyword-face" ))
1109
- (propertize plain-name 'face (intern " font-lock-function-name-face" ))
1110
- " : "
1111
- (propertize type 'face (intern " font-lock-doc-face" )))))
1112
-
1113
- ; ;;;;;;;;;;;;;;;;;;;;
1114
- ; ; SEARCH BY TYPE ;;
1115
- ; ;;;;;;;;;;;;;;;;;;;;
1094
+ ; ;;;;;;;;;;;
1095
+ ; ; SEARCH ;;
1096
+ ; ;;;;;;;;;;;
1116
1097
1117
- (defun merlin--search-by-type (query )
1098
+ (defun merlin--search (query )
1118
1099
(merlin-call " search-by-type"
1119
1100
" -query" query
1120
1101
" -position" (merlin-unmake-point (point ))))
1121
1102
1122
- (defun merlin--get-search-by-type-result-buff ()
1123
- (get-buffer-create merlin-search-by-type-buffer-name))
1124
-
1125
- (defun merlin--search-result-to-entry (entry )
1126
- (let ((function-name (cdr (assoc 'name entry)))
1127
- (function-type (cdr (assoc 'type entry))))
1128
- (list function-name (vector (merlin--render-search-result
1129
- function-name
1130
- function-type)))))
1131
-
1132
- (defun merlin-search-by-type (query )
1133
- " Search a value definition by type expression"
1134
- (interactive " sSearch query: " )
1135
- (let ((entries (merlin--search-by-type query))
1136
- (previous-buff (current-buffer )))
1137
- (let ((search-by-type-buffer (merlin--get-search-by-type-result-buff))
1138
- (inhibit-read-only t ))
1139
- (with-current-buffer search-by-type-buffer
1140
- (switch-to-buffer-other-window search-by-type-buffer)
1141
- (goto-char 1 )
1142
- (tabulated-list-mode )
1143
- (setq tabulated-list-format [(" Search By Type Result" 100 t )])
1144
- (setq tabulated-list-entries
1145
- (mapcar 'merlin--search-result-to-entry entries))
1146
- (setq tabulated-list-padding 2 )
1147
- (face-spec-set 'header-line '((t :weight bold :height 1.2 )))
1148
- (tabulated-list-init-header )
1149
- (tabulated-list-print t )
1150
- (setq buffer-read-only t )
1151
- (switch-to-buffer-other-window previous-buff)))))
1152
-
1153
- ; ;;;;;;;;;;;;;;;;;;;;
1154
- ; ; POLARITY SEARCH ;;
1155
- ; ;;;;;;;;;;;;;;;;;;;;
1156
-
1157
- (defun merlin--search (query )
1158
- (merlin-call " search-by-polarity"
1159
- " -query" query
1160
- " -position" (merlin-unmake-point (point ))))
1161
-
1162
- (defun merlin--get-polarity-buff ()
1163
- (get-buffer-create merlin-polarity-search-buffer-name))
1164
-
1165
- (defun merlin--polarity-result-to-list (entry )
1166
- (let ((function-name (merlin-completion-entry-text " " entry))
1167
- (function-type (merlin-completion-entry-short-description entry)))
1168
- (list function-name
1169
- (vector (merlin--render-search-result function-name function-type)))))
1170
-
1171
- (defun merlin-search-by-polarity (query )
1172
- " Search a value definition by polarity"
1173
- (interactive " sSearch query: " )
1174
- (let* ((result (merlin--search query))
1175
- (entries (cdr (assoc 'entries result)))
1176
- (previous-buff (current-buffer )))
1177
- (let ((pol-buff (merlin--get-polarity-buff))
1178
- (inhibit-read-only t ))
1179
- (with-current-buffer pol-buff
1180
- (switch-to-buffer-other-window pol-buff)
1181
- (goto-char 1 )
1182
- (tabulated-list-mode )
1183
- (setq tabulated-list-format [(" Polarity Search Result" 100 t )])
1184
- (setq tabulated-list-entries
1185
- (mapcar 'merlin--polarity-result-to-list entries))
1186
- (setq tabulated-list-padding 2 )
1187
- (face-spec-set 'header-line '((t :weight bold :height 1.2 )))
1188
- (tabulated-list-init-header )
1189
- (tabulated-list-print t )
1190
- (setq buffer-read-only t )
1191
- (switch-to-buffer-other-window previous-buff)))))
1192
-
1193
- (defun merlin--is-polarity-query (query )
1194
- (or (string-prefix-p " -" query) (string-prefix-p " +" query)))
1103
+ (defun merlin--search-format-key (name type doc )
1104
+ (let ((plain-name (string-remove-prefix " Stdlib__" name)))
1105
+ (concat
1106
+ (propertize plain-name 'face (intern " font-lock-function-name-face" ))
1107
+ " : "
1108
+ (propertize type 'face (intern " font-lock-doc-face" ))
1109
+ " "
1110
+ (propertize doc 'face (intern " font-lock-comment-face" )))))
1111
+
1112
+ (defun merlin--get-documentation-line-from-entry (entry )
1113
+ (let* ((doc-entry (cdr (assoc 'doc entry)))
1114
+ (doc (if (eq doc-entry 'null ) " " doc-entry))
1115
+ (doc-lines (split-string doc " [\r\n ]+" )))
1116
+ (car doc-lines)))
1117
+
1118
+ (defun merlin--search-entry-to-completion-entry (entry )
1119
+ (let ((value-name (cdr (assoc 'name entry)))
1120
+ (value-hole (cdr (assoc 'constructible entry)))
1121
+ (value-type (cdr (assoc 'type entry)))
1122
+ (value-docs (merlin--get-documentation-line-from-entry entry)))
1123
+ (let ((key (merlin--search-format-key value-name value-type value-docs))
1124
+ (value value-hole))
1125
+ (cons key value))))
1126
+
1127
+ (defun merlin--search-select-completion-result (choices selected )
1128
+ (alist-get selected choices nil nil #'equal ))
1129
+
1130
+ (defun merlin--search-substitute-constructible (elt )
1131
+ (progn
1132
+ (when (region-active-p )
1133
+ (delete-region (region-beginning ) (region-end )))
1134
+ (insert (concat " (" elt " )" ))))
1135
+
1136
+ (defun merlin--search-completion-presort (choices )
1137
+ (lambda (string pred action )
1138
+ (if (eq action 'metadata )
1139
+ '(metadata (display-sort-function . identity)
1140
+ (cycle-sort-function . identity))
1141
+ (complete-with-action action choices string pred))))
1195
1142
1196
1143
(defun merlin-search (query )
1197
- " Search a value defintion by polarity or by type expression "
1144
+ " Search values by types or polarity "
1198
1145
(interactive " sSearch query: " )
1199
- (if (merlin--is-polarity-query query)
1200
- (merlin-search-by-polarity query)
1201
- (merlin-search-by-type query)))
1146
+ (let* ((entries (merlin--search query))
1147
+ (choices
1148
+ (mapcar #'merlin--search-entry-to-completion-entry entries)))
1149
+ (let ((constructible
1150
+ (merlin--search-select-completion-result
1151
+ choices
1152
+ (completing-read (concat " Candidates: " )
1153
+ (merlin--search-completion-presort choices)
1154
+ nil nil nil t ))))
1155
+ (merlin--search-substitute-constructible constructible))))
1156
+
1202
1157
1203
1158
; ;;;;;;;;;;;;;;;;
1204
1159
; ; TYPE BUFFER ;;
0 commit comments