Debian Codegraph @

ide/rocqide/gtk_parsing.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 let underscore = Glib.Utf8.to_unichar "_" ~pos:(ref 0)
12 let prime = Glib.Utf8.to_unichar "'" ~pos:(ref 0)
13 let dot = Glib.Utf8.to_unichar "." ~pos:(ref 0)
14
15 let find_word_start (it:GText.iter) =
16 let rec aux it good =
17 if it#is_start then good
18 else
19 let it = it#backward_char in
20 let c = it#char in
21 if Glib.Unichar.isalpha c || c = underscore then aux it it
22 else if Glib.Unichar.isalnum c || c = prime || c = dot then aux it good
23 else good in
24 aux it it
25
26 let find_word_end (it:GText.iter) =
27 let rec aux it good =
28 if it#is_end then good
29 else
30 let c = it#char in
31 let it = it#forward_char in
32 if Glib.Unichar.isalnum c || c = prime || c = underscore then aux it it
33 else if c = dot then aux it good
34 else good in
35 aux it it
36
37 let starts_word (it:GText.iter) =
38 if it#is_start then true
39 else
40 let it = it#backward_char in
41 let c = it#char in
42 if Glib.Unichar.isalpha c || c = underscore then
43 it#equal (find_word_start it)
44 else false
45
46 let ends_word (it:GText.iter) =
47 if it#is_end then true
48 else
49 let c = it#char in
50 let it = it#forward_char in
51 if Glib.Unichar.isalnum c || c = prime || c = underscore then
52 it#equal (find_word_end it)
53 else false
54
55 let get_word_around (it:GText.iter) =
56 let start = find_word_start it in
57 let stop = find_word_end it in
58 start,stop
59
60 (** On double-click on a view, select the whole word. This is a workaround for
61 a deficient word handling in TextView. *)
62 let fix_double_click self =
63 let callback ev = match GdkEvent.get_type ev with
64 | `TWO_BUTTON_PRESS ->
65 let iter = self#buffer#get_iter `INSERT in
66 let start, stop = get_word_around iter in
67 let () = self#buffer#move_mark `INSERT ~where:start in
68 let () = self#buffer#move_mark `SEL_BOUND ~where:stop in
69 true
70 | _ -> false
71 in
72 ignore (self#event#connect#button_press ~callback)