-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcern-root-help.el
More file actions
1340 lines (1236 loc) · 54.6 KB
/
cern-root-help.el
File metadata and controls
1340 lines (1236 loc) · 54.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; root-help.el --- Helper functions for ROOT
;; -*- mode: emacs-lisp -*-
;;
;; $Id: root-help.el.in,v 1.1 2002/07/31 20:44:26 rdm Exp $
;;
;; Emacs lisp functions to help write ROOT based projects
;; Copyright (C) 2002, 2003 Christian Holm Christensen
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
;; 02111-1307 USA
;;
;; Author: Christian Holm Christensen <cholm@nbi.dk>
;; Maintainer: Christian Holm Christensen <cholm@nbi.dk>
;; Created: 20:34:51 Thursday 05/09/02 CEST
;; Version: 1.2
;; Keywords: oop programming
;;
;;; Commentary:
;;
;; The Emacs Lisp library `root-help.el' provides a number of
;; function to ease the development of ROOT based classes and
;; projects.
;;
;; I'll bet you, that after using this for a while, you'll never
;; want to go back to using a normal terminal for running ROOT -
;; unless you're a Vi-lover of course :-).
;;
;; Installation
;;
;; To use the Emacs Lisp library, download `root-help.el' and put
;; it somewhere Emacs looks for Lisp libraries. For people who
;; have system operator privileges, the following directories are
;; good candidates:
;;
;; /usr/share/emacs/site-lisp
;; /usr/share/emacs/<version>/site-lisp
;; /usr/local/share/emacs/site-lisp
;; /usr/local/share/emacs/<version>/site-lisp
;; /usr/lib/emacs/site-lisp
;; /usr/lib/emacs/<version>/site-lisp
;; /usr/local/lib/emacs/site-lisp
;; /usr/local/lib/emacs/<version>/site-lisp
;;
;; where `<version>' is the version number of the Emacs you're
;; using.
;;
;; For normal users, one should create the directory
;;
;; ${HOME}/share/emacs/site-lisp
;;
;; And add the line below to `~/.emacs':
;;
;; (setq load-path (cons "~/share/emacs/site-lisp" load-path))
;;
;; In any case, users that want to use the ROOT Emacs Lisp helper
;; functions should add the line below to their `~/.emacs':
;;
;; (require 'root-help)
;;
;; System operators may have some way of providing the library
;; system wide. For example on Debian systems, one can add the
;; file `/etc/emacs/site-start.d/50root-help.el' with the contents
;;
;; (require 'root-help)
;;
;; and the library functions will be available system wide. See
;; also your Emacs manual for more information.
;;
;; Functions
;;
;; All the functions in the library are invoked by typing
;;
;; M-x <function>
;;
;; where `M-x' means "Meta key down and then `x'", where the Meta
;; key is usually defined to `Alt' and `Esc', and `<function>' is
;; the function to be invoked.
;;
;; No key-bindings have been setup per default, but this is easily
;; done using the customisation support of Emacs. Alternatively
;; one can define key-bindings in ones `~/.emacs' file. For
;; example, one could bind the functions in C++ mode like this:
;;
;; (defun root-c++-mode-hook ()
;; "Hook for C++ mode - binding ROOT functions"
;; (define-key c++-mode-map "\C-crc" 'root-class)
;; (define-key c++-mode-map "\C-crh" 'root-header-skel)
;; (define-key c++-mode-map "\C-crs" 'root-source-skel)
;; (define-key c++-mode-map "\C-cri" 'root-include-header)
;; (define-key c++-mode-map "\C-crm" 'root-main)
;; (define-key c++-mode-map "\C-crl" 'root-insert-linkdef)
;; (define-key c++-mode-map "\C-crp" 'root-insert-pragma)
;; (define-key c++-mode-map "\C-crx" 'root-shell)
;; (define-key c++-mode-map "\C-crg" 'root-send-line-to-root)
;; (define-key c++-mode-map "\C-crr" 'root-send-region-to-root)
;; (define-key c++-mode-map "\C-crb" 'root-send-buffer-to-root)
;; (define-key c++-mode-map "\C-crf" 'root-execute-file))
;; (add-hook 'c++-mode-hook 'root-c++-mode-hook)
;;
;; root-class [NAME SCOPE INCDIR SRCDIR]
;; Make two new files for a ROOT based class. All arguments are
;; optional, and if not provided, the user will be prompted for
;; them. `NAME' is the name of the class. This can not be left
;; blank. `SCOPE' the preprocessor scope for header guards, or
;; `ROOT' if left blank. `INCDIR' is where the declaration file
;; will live, defaults to current directory. `SRCDIR' is where
;; the definition file will live, defaults to current directory.
;;
;; root-header-skel [SCOPE BASE DSCR]
;; Insert a skeleton for a ROOT based class The class name is
;; derived from the current buffers file name, if possible,
;; otherwise the user is prompted for it. All arguments are
;; optional. If not specified, the user will be prompted for it.
;;
;; `SCOPE' is the preprocessor scope for header guards, and
;; `BASE' is the possible base class, and `DSCR' a short doc
;; string
;;
;; root-source-skel [SCOPE DSCR]
;; Insert a skeleton for a ROOT based class The class name is
;; derived from the current buffers file name, if possible,
;; otherwise the user is prompted for it. All arguments are
;; optional. If not specified, the user will be prompted for it.
;;
;; `SCOPE' is the preprocessor scope for header guards, and DSCR
;; a short description
;;
;; root-include-header [HEADER SCOPE]
;; Insert an `#include' statement with guards for a ROOT class
;;
;; `HEADER' is the name of the class to include a header for, and
;; `SCOPE' is the optional scope, which defaults to `ROOT'. If
;; not given, `HEADER' is read from the minibuffer with
;; completion. The completion is based on the file names found in
;; `root-include-directory'.
;;
;; root-main
;; Insert a skeleton for a ROOT based program Two function will
;; be created - one which has the name of the current buffer with
;; out extensions, and which the user is to fill in, and a `main'
;; function that calls this function. Like this, we can use the
;; file for both interactive input, due to use of guards, and as
;; a program.
;;
;; The user will be prompted for whether graphics is needed or
;; not. If yes, then a `TApplication' object is created in the
;; `main' function.
;;
;; root-insert-linkdef
;; Insert lines appropriate for a linkdef file into current
;; buffer
;;
;; The user will be prompted for classes to add to the linkdef
;; file. An empty string ends the input.
;;
;; root-insert-pragma [NAME NEED-PLUS]
;; Insert a pragma linkdef line for a class All arguments are
;; optional. If not given, the user will be prompted for them.
;; `NAME' is the name of class, and if `NEED-PLUS' is non-nil, an
;; `+' will be appended to the class name line.
;;
;; root-shell [SCRIPT]
;; Start an interactive ROOT session in a buffer The executable
;; stored in `root-executable' is executed with the arguments
;; `root-executable-args'. If Emacs is running in a non-graphics
;; terminal (like a VT100) `root-executable-args-nographics' is
;; passed to the executable.
;;
;; If the optional [SCRIPT] argument is given, it should be a
;; file name that will be inserted into the session on startup.
;;
;; root-send-line-to-root
;; Sends the current line to an interactive ROOT session. If no
;; session currently exists, one will be created. The point is
;; moved down one line, and left in the current window (buffer).
;; You can use this to step throught a script.
;;
;; root-send-region-to-root [START END]
;; Sends the contents of the current region to an interactive
;; ROOT session. If no session exists, then one will be
;; created. The point is left in the current window.
;;
;; root-send-buffer-to-root
;; Sends the the current buffer to an interactive ROOT session.
;; If no session exists, then one will be created. The point is
;; left in the current window. If the buffer has an associated
;; file, and it has been modified since the last save, then the
;; user will be prompted for whether she wants to save the buffer
;; or not.
;;
;; Customisation
;;
;; The library depends on a number of variables that the user may
;; customise using Emacs' regular customisation support. All the
;; customisation is in the sub-group `Root' of the group
;; `Programming - Tools'
;;
;; root-include-directory
;; Where the ROOT headers reside. If the `ROOTSYS' environment
;; variable is set, this defaults to `${ROOTSYS}/include',
;; otherwise to `/usr/include/root'
;;
;; root-executable
;; Full path to the ROOT interactive executable. If the `ROOTSYS'
;; environment variable is set, this defaults to
;; `${ROOTSYS}/bin/root', otherwise to `/usr/bin/root'
;;
;; root-executable-args
;; Arguments to pass to `root-executable'. Per default this is
;; empty.
;;
;; root-executable-args-nographics
;; Arguments to pass to `root-executable' in case Emacs is
;; running in a non-graphics environment, like a VT100 terminal
;; or similar. Per default this is set to `"-l -b"'
;;
;; root-execute-file
;; Execute the current buffer in an interactive ROOT session.
;;
;; If no session exists, then one will be created. With a prefix
;; argument, the user is asked to provide a file name.
;;
;;____________________________________________________________________
;;
;;; Code:
;;____________________________________________________________________
(require 'term)
;;____________________________________________________________________
(defgroup root nil
"ROOT's Object Oriented Technologies helper functions"
:group 'programming
:group 'tools)
;;____________________________________________________________________
(defcustom root-include-directory
(if (getenv "ROOTSYS")
(concat (getenv "ROOTSYS") "/include")
"/usr/local/Cellar/root/5.34.36_2/include/root")
"Where the ROOT headers reside"
:group 'root)
;;____________________________________________________________________
(defcustom root-executable
(if (getenv "ROOTSYS")
(concat (getenv "ROOTSYS") "/bin/root.exe")
"/usr/local/Cellar/root/5.34.36_2/bin/root.exe")
"Full path to the ROOT interactive executable"
:group 'root)
;;____________________________________________________________________
(defcustom root-executable-args ""
"Arguments passed to the \\[root-executable]"
:group 'root)
;;____________________________________________________________________
(defcustom root-executable-args-nographics "-l -b"
"Arguments passed to the \\[root-executable] in non-graphics environment"
:group 'root)
;;____________________________________________________________________
(defface root-shell-startup-face nil
"Face to use for the startup text in the root shell"
:group 'root)
(copy-face 'default 'root-shell-startup-face)
(setq root-shell-startup-face 'root-shell-startup-face)
;;____________________________________________________________________
(defface root-shell-prompt-face nil
"Face to use for the prompt in the root shell"
:group 'root)
(copy-face 'underline 'root-shell-prompt-face)
(setq root-shell-prompt-face 'root-shell-prompt-face)
;;____________________________________________________________________
(defface root-shell-keyword-face nil
"Face to for keywords in the root shell"
:group 'root)
(copy-face 'font-lock-keyword-face 'root-shell-keyword-face)
(setq root-shell-keyword-face 'root-shell-keyword-face)
;;____________________________________________________________________
(defface root-shell-warning-face nil
"Face to for warnings and errors in the root shell"
:group 'root)
(copy-face 'font-lock-warning-face 'root-shell-warning-face)
(setq root-shell-warning-face 'root-shell-warning-face)
;;____________________________________________________________________
(defface root-shell-string-face nil
"Face to for strings in the root shell"
:group 'root)
(copy-face 'font-lock-string-face 'root-shell-string-face)
(setq root-shell-string-face 'root-shell-string-face)
;;____________________________________________________________________
(defface root-shell-constant-face nil
"Face to for constants in the root shell"
:group 'root)
(if (string-match "XEmacs\\|Lucid" emacs-version)
(copy-face 'default 'root-shell-constant-face)
(copy-face 'font-lock-constant-face 'root-shell-constant-face))
(setq root-shell-constant-face 'root-shell-constant-face)
;;____________________________________________________________________
(defface root-shell-variable-face nil
"Face to for variables in the root shell"
:group 'root)
(copy-face 'font-lock-variable-name-face 'root-shell-variable-face)
(setq root-shell-variable-face 'root-shell-variable-face)
;;____________________________________________________________________
(defface root-shell-function-face nil
"Face to for functions in the root shell"
:group 'root)
(copy-face 'font-lock-function-name-face 'root-shell-function-face)
(setq root-shell-function-face 'root-shell-function-face)
;;____________________________________________________________________
(defface root-shell-builtin-face nil
"Face to for builtins in the root shell"
:group 'root)
(if (string-match "XEmacs\\|Lucid" emacs-version)
(copy-face 'font-lock-keyword-face 'root-shell-builtin-face)
(copy-face 'font-lock-builtin-face 'root-shell-builtin-face))
(setq root-shell-builtin-face 'root-shell-builtin-face)
;;____________________________________________________________________
(defface root-shell-type-face nil
"Face to for types in the root shell"
:group 'root)
(copy-face 'font-lock-type-face 'root-shell-type-face)
(setq root-shell-type-face 'root-shell-type-face)
;;____________________________________________________________________
(defun root-class (&optional name scope incdir srcdir dscr)
"Make two new files for a ROOT based class.
All arguments are optional, and if not provided, the user will be
prompted for them.
NAME is the name of the class. This can not be left blank. SCOPE the
preprocessor scope for header guards, or 'ROOT' if left blank. INCDIR
is where the declaration file will live, defaults to current
directory. SRCDIR is where the definition file will live, defaults
to current directory. DSCR is the short description.
Uses \\[root-header-skel] and \\[root-source-skel]"
(interactive)
;; Read the class name from the minibuffer is the user didn't supply
;; one
(while (or (not name) (string= name ""))
;; If that's not possible prompt user for it
(setq name (read-string "Class name: ")))
;; Get the preprocessor scope if not passed by user
(if (not scope) (setq scope (read-string "Scope: ")))
;; Figure out where to put the declaration file
(if (not incdir)
(setq incdir (read-string "Declaration directory (.): ")))
;; Set default if user types C-j
(if (eq (length incdir) 0) (setq incdir "."))
;; Figure out where to put the declaration file
(if (not srcdir)
(setq srcdir (read-string "Implementation directory (.): ")))
;; Set default if user types C-j
(if (eq (length srcdir) 0) (setq srcdir "."))
;; Make file names
(let ((header-name) (source-name))
(setq header-name (if (string= "." incdir) (concat name ".h")
(concat incdir "/" name ".h")))
(setq source-name (if (string= "." srcdir) (concat name ".cxx")
(concat srcdir "/" name ".cxx")))
;; Check that files doesn't exist
(if (file-exists-p header-name)
(error "Header file '%s' already exists - will not overwrite"
header-name))
(if (file-exists-p source-name)
(error "Source file '%s' already exists - will not overwrite"
source-name))
;; Check files are writable
(if (not (file-writable-p header-name))
(error "Cannot write header file '%s'" header-name))
(if (not (file-writable-p source-name))
(error "Cannot write source file '%s'" source-name))
;; Open the header file and make that current buffer
(find-file header-name)
(c++-mode)
;; Write the header skeleton
(root-header-skel scope)
;; Save the file
(save-buffer)
;; Open the source file and make that current buffer
(if (not (string= incdir "."))
(find-file-other-window (concat "../" source-name))
(find-file-other-window source-name))
;; Write the source skeleton
(root-source-skel scope)
;; Save the file
(save-buffer)
;; Write a message to user
(message "Class is in '%s' and '%s'" header-name source-name)))
;;____________________________________________________________________
(defun root-header-skel (&optional scope base dscr)
"Insert a skeleton for a ROOT based class
The class name is derived from the current buffers file name, if
possible, otherwise the user is prompted for it. All arguments are
optional. If not specified, the user will be prompted for it.
SCOPE is the preprocessor scope for header guards, BASE is the
possible base class, and DSCR is a short description of the class"
(interactive)
(let (name)
;; Get the class name form the filename of the buffer
(setq name (file-name-sans-extension (buffer-name)))
;; If that failed, prompt the user for it
(while (or (not name) (string= name ""))
;; If that's not possible prompt user for it
(setq name (read-string "Class name: ")))
;; If the scope isn't set,
(if (or (not scope) (string= "" scope)) (setq scope "ROOT"))
;; If the base file isn't set, prompt the user for it.
(if (or (not base) (string= "" base))
(setq base (root-read-class "Base class: " "TObject")))
;; Get a description string
(if (or (not dscr) (string= dscr ""))
(setq dscr (read-string "Documentation: " "DOCUMENT ME")))
;; Go to the top of the file
(goto-char (point-min))
(insert "// -*- mode: c++ -*- \n")
(root-insert-header-info)
(insert "#ifndef " scope "_" name "\n#define " scope "_" name "\n")
(if (and base (not (string= base ""))) (root-include-header base))
(insert "\nclass " name)
(if (and base (not (string= base ""))) (insert " : public " base))
(insert "
{
private:
public:
" name "();
virtual ~" name "() {}
ClassDef(" name ",0) //" dscr "
};
#endif
")
(root-insert-bottom-info)
(goto-char (point-min))))
;;____________________________________________________________________
(defun root-source-skel (&optional scope dscr)
"Insert a skeleton for a ROOT based class
The class name is derived from the current buffers file name, if
possible, otherwise the user is prompted for it. All arguments are
optional. If not specified, the user will be prompted for it.
SCOPE is the preprocessor scope for header guards, and DSCR is a
description string."
(interactive)
(let (name)
;; Get the class name form the filename of the buffer
(setq name (file-name-sans-extension (buffer-name)))
;; If that failed, prompt the user for it
(while (or (not name) (string= name ""))
;; If that's not possible prompt user for it
(setq name (read-string "Class name: ")))
;; If the scope isn't set,
(if (or (not scope) (string= "" scope)) (setq scope "ROOT"))
;; Get a description string
(if (or (not dscr) (string= dscr ""))
(setq dscr (read-string "Long description: " "DOCUMENT ME")))
(goto-char (point-min))
;; Insert a skeleton for the class description
(insert
"//____________________________________________________________________
//
// " dscr "
//
")
;; Insert author, date, copyright information
(root-insert-header-info)
;; Include the class declaration
(root-include-header name scope)
;; Insert a dummy CTOR and class implementation macro
(insert "
//____________________________________________________________________
ClassImp(" name ");
//____________________________________________________________________
" name "::" name "()
{
// Default constructor
}
")
(root-insert-bottom-info)
(goto-char (point-min))))
;;____________________________________________________________________
(defun root-insert-header-info ()
"Inserts some lines for a header, including CVS Id, author, date copyright"
(insert
"//____________________________________________________________________
//
// $Id" "$
// Author: " (user-full-name) " <" user-mail-address ">
// Update: " (format-time-string "%Y-%m-%d %T%z") "
// Copyright: " (format-time-string "%Y") " (C) " (user-full-name) "
//
"))
;;____________________________________________________________________
(defun root-insert-bottom-info ()
"Inserts some lines for a footer"
(insert
"//____________________________________________________________________
//
// EOF
//
"))
;;____________________________________________________________________
(defun root-include-header (&optional header scope)
"Insert an #include statement with guards for a ROOT class
HEADER is the name of the class to include a header for, and SCOPE is
the optional scope, which defauls to 'ROOT'. If not given, HEADER is
read from the minibuffer _with_ completion. The completion is based on
the file names found in \\[root-include-directory]"
(interactive)
;; Read the class name (with completion) from user if it isn't given
;; already
(if (not header) (setq header (root-read-class "Class name: " nil)))
;; If the scope ins't set, set it to ROOT
(if (or (not scope) (string= "" scope)) (setq scope "ROOT"))
;; Insert the lines we need
(insert "#ifndef " scope "_" header
"\n#include \"" header ".h\"\n#endif\n"))
;;____________________________________________________________________
(defun root-main ()
"Insert a skeleton for a ROOT based program
Two function will be created - one which has the name of the current
buffer with out extensions, and which the user is to fill in, and a
'main' function that calls this function. Like this, we can use the
file for both interactive input, due to use of guards, and as a
program.
The user will be prompted for wether graphics is needed or not. If
yes, then a TApplication object is created in the main function."
(interactive)
;;
(let (name)
(setq name (file-name-sans-extension (buffer-name)))
(setq need-application (y-or-n-p "Do you need graphics "))
(goto-char (point-min))
(root-insert-header-info)
(insert "//\n#ifndef __CINT__\n")
(if need-application (root-include-header "TApplication"))
(insert "// PUT HEADERS HERE
#endif
int " name "()
{
// DEFINE YOUR MAIN FUNCTION HERE
return 0;
}
#ifndef __CINT__
int main(int argc, char** argv)
{
")
(if need-application
;; If we need an application, then we insert, that, store the
;; return value of the function, run the application, and
;; return the stored return value.
(insert "TApplication " name "App(\"" name "App\", &argc, argv);
int retVal = " name "();
" name "App.Run();
return retVal;")
;; Otherwise we just insert the call
(insert "return " name "();"))
;; Closing brace
(insert "\n}\n#endif\n\n")
;; Bottom of the file
(root-insert-bottom-info)
(goto-char (point-min))))
;;____________________________________________________________________
(defun root-insert-linkdef ()
"Insert lines appropriate for a linkdef file into current buffer
The user will be prompted for classes to add to the linkdef file. An
empty string ends the input."
(interactive)
(insert "// -*- mode: c++ -*-\n")
(root-insert-header-info)
(insert "
#ifndef __CINT__
#error Not for compilation
#endif
#pragma link off all functions;
#pragma link off all globals;
#pragma link off all classes;
")
;; Let the user add classes right away
(while
(progn (setq name (read-string "Add a class: "))
(> (length name) 0))
(root-insert-pragma name))
;; insert a new line and the end stuff
(insert "\n")
(root-insert-bottom-info)
(goto-char (point-min)))
;;____________________________________________________________________
(defun root-insert-pragma (&optional name need-plus)
"Insert a pramga linkdef line for a class
All arguments are optional. If not given, the user will be prompted
for them. NAME is the name of class, and if NEED-PLUS is non-nil, an
'+' will be appended to the class name line."
(interactive)
;; Read the class name
(while (or (not name) (string= name ""))
;; If that's not possible prompt user for it
(setq name (read-string "Class name: ")))
;; Check if we need a plus or not.
(if (not need-plus)
(setq need-plus (y-or-n-p "Do you schema evolution ")))
;; Insert the actual line
(insert "#pragma link C++ class " name)
;; insert the plus if we need it.
(if need-plus (insert "+"))
;; and a final newline
(insert ";\n"))
;;____________________________________________________________________
(defun root-complete-class (name filter flag)
"Completition function for root-read-class.
It looks up the passed name in the ROOT header directory set by
\\[root-include-directory], and does the matching on files there."
(if flag
;; Return a list of all possible completions
(let (files)
(setq files
(file-name-all-completions name root-include-directory))
(if (not files) (error "no matches on '%s'" name))
(mapcar 'file-name-sans-extension files))
;; Returns:
;; t if an exact match is found,
;; nil if no possible match is found,
;; completion if unique
;; Longest possible completion if not
(let (first)
(setq first (file-name-completion name root-include-directory))
(if (and (stringp first) (string= first (concat name ".h")))
t
(progn
(if (stringp first)
(file-name-sans-extension first)))))))
;;____________________________________________________________________
(defun root-read-class (prompt default)
"Interactively read the name of a ROOT class.
Completion is done based on the file names found in
\\[root-include-directory]"
(completing-read prompt 'root-complete-class nil nil default))
;;____________________________________________________________________
(defun sys-include-header (&optional header)
"Insert an #include for a system header"
(interactive)
(if (not header)
(setq header (read-string "Header name: ")))
(insert "#ifndef __" (upcase header) "__\n"
"#include <" (symbol-value 'header) ">\n"
"#endif\n"))
;;____________________________________________________________________
(defvar root-shell-font-lock-keywords
'(("^ \\*+$" . root-shell-startup-face)
("^ \\*.*\\*$" . root-shell-startup-face)
("^Compiled for.*$" . root-shell-startup-face)
("^CINT/ROOT C/C\\+\\+ .*$" . root-shell-startup-face)
("^Type \\? for help\\. Commands must be .*$" . root-shell-startup-face)
("^Enclose multiple statements.*$" . root-shell-startup-face)
("^FreeType Engine .* used to render.*$" . root-shell-startup-face)
("root \\[[0-9]+\\]" . root-shell-prompt-face)
("Root *>" . root-shell-prompt-face)
("end with '.'[^>]*>" . root-shell-prompt-face)
("^ *\\*+ Interpreter error recovered \\*+$" . root-shell-warning-face)
("^ *\\*+ Break \\*+ " . root-shell-warning-face)
("^\\(Sys\\)?Error" . root-shell-warning-face)
("^Warning" . root-shell-warning-face)
("^Fatal" . root-shell-warning-face)
("\"[^\"]*\"" . root-shell-string-face)
("0[xX][0-9A-Fa-f]+" . root-shell-constant-face)
("[+-]?[0-9]+\\.?[0-9]*[eE][+-]?[0-9]+[lL]?" . root-shell-constant-face)
("[+-]?[0-9]*\\.[0-9]+[eE][+-]?[0-9]+[lL]?" . root-shell-constant-face)
("\\b[+-]?[0-9]+\\.?[0-9]*[uUlL]?\\b" . root-shell-constant-face)
("\\b[+-]?[0-9]*\\.[0-9][uUlL]?\\b" . root-shell-constant-face)
("\\(//.*\\|/\\*.*\\*/\\)" . root-shell-comment-face)
("\(\\sw+\\s-*\)(" . root-shell-function-face)
("\\b\\sw+_t\\b" . root-shell-type-face)
("\\(T[A-Z]\\sw+\\|E[A-Z]\\sw+\\)" . root-shell-type-face)
("\\b\\(const_\\)?iterator\\b" . root-shell-type-face)
("\\b\\([io]+\\|[io]?[f]\\)stream\\b" . root-shell-type-face)
("\\b[io]?strstream\\b" . root-shell-type-face)
("\\b\\(if\\|else\\|for\\|while\\|do\\)\\b" . root-shell-keyword-face)
("\\b\\(case\\|switch\\)\\b" . root-shell-keyword-face)
("\\b\\(typedef\\|typename\\|typeid\\)\\b" . root-shell-keyword-face)
("\\b\\(class\\|struct\\)\\b" . root-shell-keyword-face)
("\\b\\(new\\|delete\\|sizeof\\)\\b" . root-shell-keyword-face)
("\\b\\(register\\|static\\|mutable\\)\\b" . root-shell-keyword-face)
("\\b\\(volatile\\|const\\)\\b" . root-shell-keyword-face)
("\\b\\(private\\|protected\\|public\\)\\b" . root-shell-keyword-face)
("\\b\\(cout\\|cerr\\|cin\\|endl\\)\\b" . root-shell-variable-face)
("\\b\\(flush\\|setw\\|setprecision\\)\\b" . root-shell-variable-face)
("\\b\\(gROOT\\|gStyle\\)\\b" . root-shell-variable-face)
("\\b\\(gApplication\\|gPad\\)\\b" . root-shell-variable-face)
("\\b\\(int\\|short\\|long\\|unsigned\\)\\b" . root-shell-type-face)
("\\b\\(float\\|double\\|char\\)\\b" . root-shell-type-face)
("\\b\\(map\\|vector\\|list\\|multimap\\)\\b" . root-shell-type-face)
("\\b\\(string\\|complex\\|streambuf\\)\\b" . root-shell-type-face)
("\\b\\(exception\\|runtime_error\\)\\b" . root-shell-type-face)
("\\.\\S-+" . root-shell-builtin-face)
)
"Additional expressions to highlight in ROOT intaractive mode.")
;;____________________________________________________________________
(defconst root-name "ROOT"
"The name of ROOT")
;;____________________________________________________________________
(defconst root-shell-buffer (concat "*" root-name "*")
"The name of the root-shell buffer")
;;____________________________________________________________________
(defun root-shell-histo (dimension type)
"Make a histogram in the interactive shell"
(interactive (list
(let ((d 0))
(while (<= d 0)
(setq d (string-to-int (read-string "Dimension: ")))) d)
(read-char "Type: ")))
(let ((type (format "TH%d%c" dimension (upcase type)))
(name "h")
(command nil))
(while (progn
(setq name (read-string "Name: " name))
(string= name "")))
(setq command (concat type "* " name " = new " type "(\"" name "\",\""))
(setq command (concat command (read-string "Title: " ) "\","))
(dotimes (i dimension)
(let ((bins "") (low "") (high ""))
(setq axis (cond ((= i 0) "X") ((= i 1) "Y") ((= i 2) "Z")))
(while
(progn
(setq bins (read-string (concat "# of " axis " bins: ")))
(<= (string-to-int bins) 0)))
(setq command (concat command bins ","))
(setq low (read-string (concat axis " minimum: ")))
(setq command (concat command low ","))
(while
(progn
(setq high (read-string (concat axis " maximum: ")))
(> (string-to-int low) (string-to-int high))))
(setq command (concat command high
(cond ((= (1+ i) dimension) ")") (t ","))))))
(root-shell-paste (concat command ";\n") nil)))
;;____________________________________________________________________
(defun root-shell-histo-1c () "" (interactive) (root-shell-histo 1 ?C))
(defun root-shell-histo-1s () "" (interactive) (root-shell-histo 1 ?S))
(defun root-shell-histo-1f () "" (interactive) (root-shell-histo 1 ?F))
(defun root-shell-histo-1d () "" (interactive) (root-shell-histo 1 ?D))
(defun root-shell-histo-1k () "" (interactive) (root-shell-histo 1 ?K))
;;____________________________________________________________________
(defun root-shell-histo-2c () "" (interactive) (root-shell-histo 2 ?C))
(defun root-shell-histo-2s () "" (interactive) (root-shell-histo 2 ?S))
(defun root-shell-histo-2f () "" (interactive) (root-shell-histo 2 ?F))
(defun root-shell-histo-2d () "" (interactive) (root-shell-histo 2 ?D))
(defun root-shell-histo-2k () "" (interactive) (root-shell-histo 2 ?K))
;;____________________________________________________________________
(defun root-shell-histo-3c () "" (interactive) (root-shell-histo 3 ?C))
(defun root-shell-histo-3s () "" (interactive) (root-shell-histo 3 ?S))
(defun root-shell-histo-3f () "" (interactive) (root-shell-histo 3 ?F))
(defun root-shell-histo-3d () "" (interactive) (root-shell-histo 3 ?D))
(defun root-shell-histo-3k () "" (interactive) (root-shell-histo 3 ?K))
;;____________________________________________________________________
(defun root-shell-browser () "" (interactive)
(root-shell-paste "TBrowser* b = new TBrowser(\"b\", \"Browser\");\n" nil))
;;____________________________________________________________________
(defun root-shell-canvas () "" (interactive)
(root-shell-paste "TCanvas* c = new TCanvas(\"c\", \"Canvas\");\n" nil))
;;____________________________________________________________________
(defun root-shell-file (&optional file mode)
""
(interactive)
(if (or (not file) (string= "file"))
(progn
(setq file (read-file-name "File to open: "))
(if (and file (not (file-directory-p file)))
(setq file (expand-file-name file))
(error "No file to open"))))
(if (not (file-exists-p file)) (setq mode "RECREATE"))
(if (not mode) (setq mode (read-string "How to open the file: " "READ")))
(root-shell-paste (concat "TFile* file = TFile::Open(\"" file
"\",\"" mode "\");\n") nil))
;;____________________________________________________________________
(defun root-shell-command (command &optional arg file yn)
""
(let ((command (concat "." command)))
(if arg
(if file
(progn
(setq file (read-file-name arg))
(if (and file (not (file-directory-p file)))
(setq file (expand-file-name file))
(error "No file argument given to %s" command))
(setq command (concat command " " file)))
(if yn
(if (y-or-n-p (concat "Turn on " arg " "))
(setq command (concat command " 1"))
(setq command (concat command " 0"))))
(setq command (concat command " "(read-string arg)))))
(root-shell-paste (concat command "\n") nil)))
(defun root-shell-redirect-output () ""
(interactive) (root-shell-command ">" "Output file: " t))
(defun root-shell-redirect-error () ""
(interactive) (root-shell-command "2>" "Error file: " t))
(defun root-shell-redirect-both () ""
(interactive) (root-shell-command ">&" "File: " t))
(defun root-shell-help () ""
(interactive) (root-shell-command "help"))
(defun root-shell-help-search () ""
(interactive) (root-shell-command "/" "Keyword: "))
(defun root-shell-shell () ""
(interactive) (root-shell-command "!" "Shell command: "))
(defun root-shell-view () ""
(interactive) (root-shell-command "v" "Line: "))
(defun root-shell-view-stack () ""
(interactive) (root-shell-command "V" "Line: "))
(defun root-shell-trace () ""
(interactive) (root-shell-command "t"))
(defun root-shell-debug-file () ""
(interactive) (root-shell-command "f" "File: " t))
(defun root-shell-toggle-trace () ""
(interactive) (root-shell-command "T"))
(defun root-shell-toggle-auto () ""
(interactive) (root-shell-command "A" "automatic variables" nil t))
(defun root-shell-trace-class () ""
(interactive) (root-shell-command "trace" "Class: "))
(defun root-shell-untrace-class () ""
(interactive) (root-shell-command "deltrace" "Class: "))
(defun root-shell-print-expr () ""
(interactive) (root-shell-command "p" "Expression: "))
(defun root-shell-step-expr () ""
(interactive) (root-shell-command "s" "Expression: "))
(defun root-shell-step-over-expr () ""
(interactive) (root-shell-command "S" "Expression: "))
(defun root-shell-exec-file () ""
(interactive) (root-shell-command "x" "File: " t))
(defun root-shell-exec-filefunc () ""
(interactive) (root-shell-command "X" "File: " t))
(defun root-shell-edit () ""
(interactive) (root-shell-command "E" "File (optional): " t))
(defun root-shell-load () ""
(interactive) (root-shell-command "L" "File: " t))
(defun root-shell-reload () ""
(interactive) (root-shell-command "La" "File: " t))
(defun root-shell-unload () ""
(interactive) (root-shell-command "U" "File: " t))
(defun root-shell-toggle-copy () ""
(interactive) (root-shell-command "C" "copy to temporary directory" nil t))
(defun root-shell-undo () ""
(interactive) (root-shell-command "undo"))
(defun root-shell-lang () ""
(interactive) (root-shell-command "lang"))
(defun root-shell-global () ""
(interactive) (root-shell-command "g" "Global variable (empty for all): "))
(defun root-shell-local () ""
(interactive) (root-shell-command "l" "Local Variable (empty for all): "))
(defun root-shell-class () ""
(interactive) (root-shell-command "class" "Class (empty for all): "))
(defun root-shell-class-all () ""
(interactive) (root-shell-command "Class" "Class (empty for all): "))
(defun root-shell-typedef () ""
(interactive) (root-shell-command "typedef" "Type (empty for all): "))
(defun root-shell-function () ""
(interactive) (root-shell-command "function"))
(defun root-shell-macro () ""
(interactive) (root-shell-command "macro"))
(defun root-shell-template () ""
(interactive) (root-shell-command "template"))
(defun root-shell-include () ""
(interactive) (root-shell-command "include"))
(defun root-shell-files () ""
(interactive) (root-shell-command "file"))
(defun root-shell-where () ""
(interactive) (root-shell-command "where"))
(defun root-shell-security () ""
(interactive) (root-shell-command "security"))
(defun root-shell-refcount () ""
(interactive) (root-shell-command "refcount"))
(defun root-shell-garbage () ""
(interactive) (root-shell-command "garbage"))
(defun root-shell-do-garbage () ""
(interactive) (root-shell-command "Garbage"))
(defun root-shell-cover () ""
(interactive) (root-shell-command "cover" "File: " t))
(defun root-shell-return () ""
(interactive) (root-shell-command "return" "Value: "))
(defun root-shell-ignore () ""
(interactive) (root-shell-command "i"))
(defun root-shell-continue () ""
(interactive) (root-shell-command "c" "Line (optional): "))
(defun root-shell-step-out () ""
(interactive) (root-shell-command "e"))
(defun root-shell-break () ""
(interactive) (root-shell-command "break" "Line: "))
(defun root-shell-del-break () ""
(interactive) (root-shell-command "db" "Line: "))
(defun root-shell-assert () ""
(interactive) (root-shell-command "a" "Expression (blank to turn off): "))
(defun root-shell-optimization () ""
(interactive) (root-shell-command "O" "Level [0-4]: "))
(defun root-shell-toggle-debug () ""
(interactive) (root-shell-command "debug"))
(defun root-shell-toggle-disassembler () ""
(interactive) (root-shell-command "dasm"))
(defun root-shell-quit () ""
(interactive) (root-shell-command "q"))
(defun root-shell-force-quit () ""
(interactive) (root-shell-command "qqq"))
(defun root-shell-save () ""
(interactive) (root-shell-command "save"))
;;____________________________________________________________________
(defvar root-shell-mode-map nil "Mode map for \\[root-shell-mode]")
(defun root-shell-mode-make-map ()
"Defines the keymap. This _must_ be called after \\[term-char-mode],
otherwise, the parent mode \\[term-raw-map] is not defined yet, hence
this function"
(cond
((not root-shell-mode-map)
(let (map menumap menumap-top)
;; Top-level keymap
(if (string-match "XEmacs\\|Lucid" emacs-version)
(progn
(set-keymap-parents map (list term-raw-map))
(set-keymap-name map 'root-shell-mode-map))
(setq map (nconc (make-sparse-keymap) term-raw-map)))
(define-key map "\C-crh" 'root-shell-histo)
(define-key map "\C-crb" 'root-shell-browser)
(define-key map "\C-crc" 'root-shell-canvas)
(define-key map "\C-crx" 'root-shell-script)
(define-key map "\C-crf" 'root-shell-file)
;; ROOT menu map
(setq menumap-top (make-sparse-keymap "ROOT"))
;; Misc menu
(setq menumap (make-sparse-keymap "Miscellaneous"))
(define-key menumap [root-shell-save]
'("Emergency save" . root-shell-save))
(define-key menumap [root-shell-force-quit]