Skip to content

Commit ee9cdd7

Browse files
authored
Remove '--numeric' option and recovery feature (#2333)
1 parent ca4d971 commit ee9cdd7

File tree

136 files changed

+10
-10282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+10
-10282
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Removed
44

5+
- Remove `--numeric` feature (#2333, @gpetiot)
6+
57
### Deprecated
68

79
### Bug fixes

bench/bench.ml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type input =
2121
; kind: Syntax.t
2222
; source: string
2323
; conf: Conf.t
24-
; action: [`Format | `Numeric of range] }
24+
; action: [`Format] }
2525

2626
let inputs =
2727
let dir = "_build/default/bench/test" in
@@ -31,13 +31,7 @@ let inputs =
3131
; kind= Syntax.Structure
3232
; source= source_ml
3333
; conf= Conf.default
34-
; action= `Format }
35-
; { name= "numeric:conventional"
36-
; input_name= "source.ml"
37-
; kind= Syntax.Structure
38-
; source= source_ml
39-
; conf= Conf.default
40-
; action= `Numeric (10_000, 10_000) } ]
34+
; action= `Format } ]
4135

4236
let tests =
4337
List.map
@@ -50,12 +44,7 @@ let tests =
5044
| `Format ->
5145
ignore
5246
(Translation_unit.parse_and_format kind ~input_name ~source
53-
conf )
54-
| `Numeric range ->
55-
let range = Range.make source ~range in
56-
ignore
57-
(Translation_unit.numeric kind ~input_name ~source ~range conf)
58-
) )
47+
conf ) ) )
5948
inputs
6049

6150
let benchmark () =

bin/ocamlformat/main.ml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,6 @@ let run_action action =
8484
in
8585
Result.combine_errors_unit (List.map inputs ~f)
8686
| Print_config conf -> Conf.print_config conf ; Ok ()
87-
| Numeric {kind; file; name= input_name; conf} ->
88-
let conf =
89-
{ conf with
90-
opr_opts=
91-
{ conf.opr_opts with
92-
quiet= {v= true; from= conf.opr_opts.quiet.from} } }
93-
in
94-
let source = source_from_file file in
95-
let range = conf.opr_opts.range.v source in
96-
Translation_unit.numeric kind ~input_name ~source ~range conf
97-
|> List.iter ~f:(fun i -> Stdio.print_endline (Int.to_string i)) ;
98-
Ok ()
9987
;;
10088

10189
match Bin_conf.action () with

doc/manpage_ocamlformat.mld

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,11 +600,6 @@ OPTIONS
600600
--no-version-check
601601
Unset version-check.
602602

603-
--numeric
604-
Instead of re-formatting the file, output one integer per line
605-
corresponding to the indentation value, printing as many values as
606-
lines in the document.
607-
608603
-o DST, --output=DST
609604
Output file. Mutually exclusive with --inplace. Write to stdout if
610605
omitted.

emacs/ocamlformat.el

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -295,143 +295,6 @@ is nil."
295295
(delete-file bufferfile)
296296
(delete-file outputfile))))
297297

298-
(defun ocamlformat-args (name start-line end-line)
299-
(let*
300-
((margin-args
301-
(cond
302-
((equal ocamlformat-margin-mode 'window)
303-
(list "--margin" (number-to-string (window-body-width))))
304-
((equal ocamlformat-margin-mode 'fill)
305-
(list "--margin" (number-to-string fill-column)))
306-
(t
307-
'())))
308-
(enable-args
309-
(cond
310-
((equal ocamlformat-enable 'disable)
311-
(list "--disable"))
312-
((equal ocamlformat-enable 'enable-outside-detected-project)
313-
(list "--enable-outside-detected-project"))
314-
(t
315-
'())))
316-
(extension-args
317-
(cond
318-
((eq ocamlformat-file-kind 'implementation)
319-
(list "--impl"))
320-
((eq ocamlformat-file-kind 'interface)
321-
(list "--intf")))))
322-
(append margin-args enable-args extension-args
323-
(list
324-
"-"
325-
"--name" name
326-
"--numeric"
327-
"--range" (format "%d-%d" start-line end-line)))))
328-
329-
(defun ocamlformat-region (start end)
330-
(interactive "r")
331-
(let*
332-
((ext (file-name-extension buffer-file-name t))
333-
(bufferfile (file-truename (make-temp-file "ocamlformat" nil ext)))
334-
(errorfile (file-truename (make-temp-file "ocamlformat" nil ext)))
335-
(errbuf
336-
(cond
337-
((eq ocamlformat-show-errors 'buffer)
338-
(get-buffer-create "*compilation*"))
339-
((eq ocamlformat-show-errors 'echo)
340-
(get-buffer-create "*OCamlFormat stderr*"))))
341-
(start-line (line-number-at-pos start))
342-
(end-line (line-number-at-pos end))
343-
(indents-str
344-
(with-output-to-string
345-
(if (/= 0
346-
(apply 'call-process-region
347-
(point-min) (point-max) ocamlformat-command nil
348-
(list standard-output errorfile) nil
349-
(ocamlformat-args buffer-file-name start-line end-line)))
350-
(progn
351-
(if errbuf
352-
(progn
353-
(with-current-buffer errbuf
354-
(setq buffer-read-only nil)
355-
(erase-buffer))
356-
(ocamlformat--process-errors
357-
(buffer-file-name) bufferfile errorfile errbuf)))
358-
(message "Could not apply ocamlformat")))))
359-
(indents (mapcar 'string-to-number (split-string indents-str))))
360-
(unwind-protect
361-
(save-excursion
362-
(goto-char start)
363-
(mapcar
364-
#'(lambda (indent) (indent-line-to indent) (forward-line))
365-
indents))
366-
(delete-file errorfile)
367-
(delete-file bufferfile))))
368-
369-
(defun ocamlformat-line ()
370-
(interactive nil)
371-
(ocamlformat-region (point) (point)))
372-
373-
(defun ocamlformat--enable-indent ()
374-
"Whether the indentation feature is enabled."
375-
(version<= "0.19.0" (ocamlformat-version)))
376-
377-
;;;###autoload
378-
(defun ocamlformat-setup-indent ()
379-
(interactive nil)
380-
(when (ocamlformat--enable-indent)
381-
(setq-local indent-line-function #'ocamlformat-line)
382-
(setq-local indent-region-function #'ocamlformat-region)))
383-
384-
;;;###autoload
385-
(defun ocamlformat-caml-mode-setup ()
386-
(ocamlformat-setup-indent)
387-
(local-unset-key "\t")) ;; caml-mode rebinds TAB !
388-
389-
(defun ocamlformat-newline-and-indent (&optional arg)
390-
"Insert a newline, then indent according to `ocamlformat-line'.
391-
With ARG, perform this action that many times."
392-
(interactive "*p")
393-
(delete-horizontal-space t)
394-
(unless arg
395-
(setq arg 1))
396-
(dotimes (_ arg)
397-
(newline nil t)
398-
(insert "x")
399-
(ocamlformat-line)
400-
(delete-char -1)))
401-
402-
(defun ocamlformat-set-newline-and-indent ()
403-
"Bind RET to `ocamlformat-newline-and-indent'."
404-
(when (ocamlformat--enable-indent)
405-
(local-set-key (kbd "RET") 'ocamlformat-newline-and-indent)))
406-
407-
(defun ocamlformat-version ()
408-
"Get the version of the installed ocamlformat."
409-
(car
410-
(split-string
411-
(shell-command-to-string
412-
(format "%s --version" (shell-quote-argument ocamlformat-command)))
413-
"-"
414-
t
415-
split-string-default-separators)))
416-
417-
(defun ocamlformat--add-hooks ()
418-
"Link ocamlformat with tuareg-mode and caml-mode."
419-
(progn
420-
(add-hook 'tuareg-mode-hook 'ocamlformat-setup-indent t)
421-
(add-hook 'tuareg-mode-hook 'ocamlformat-set-newline-and-indent)
422-
(add-hook 'caml-mode-hook 'ocamlformat-caml-mode-setup t)
423-
(add-hook 'caml-mode-hook 'ocamlformat-set-newline-and-indent)))
424-
425-
(pcase ocamlformat-enable
426-
;; never hook
427-
('disable '())
428-
;; always hook
429-
('enable-outside-detected-project (ocamlformat--add-hooks))
430-
;; only hook if there is an .ocamlformat file at the root of the project
431-
('enable
432-
(if (vc-find-root default-directory ".ocamlformat")
433-
(ocamlformat--add-hooks))))
434-
435298
(provide 'ocamlformat)
436299

437300
;;; ocamlformat.el ends here

lib/Conf_t.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ type opr_opts =
131131
; ocaml_version: Ocaml_version.t elt
132132
(** Version of OCaml syntax of the output. *)
133133
; quiet: bool elt
134-
; range: (string -> Range.t) elt
134+
; range: (string -> Range.t) elt (** Unused. *)
135135
; disable_conf_attrs: bool elt
136136
; version_check: bool elt }
137137

lib/Indent.ml

Lines changed: 0 additions & 117 deletions
This file was deleted.

lib/Indent.mli

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)