forked from technomancy/emacs-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclearcase.el
More file actions
executable file
·7979 lines (6705 loc) · 283 KB
/
Copy pathclearcase.el
File metadata and controls
executable file
·7979 lines (6705 loc) · 283 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
;;; clearcase.el --- ClearCase/Emacs integration.
;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2006, 2007 Kevin Esler
;; Author: Kevin Esler <kaesler@us.ibm.com>
;; Maintainer: Kevin Esler <kaesler@us.ibm.com>
;; Keywords: clearcase tools
;; Web home: http://members.verizon.net/~kevin.a.esler/EmacsClearCase
;; This file is not part of GNU Emacs.
;;
;; 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, 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
;; GNU Emacs; see the file COPYING. If not, write to the Free Software
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;;{{{ Introduction
;; This is a ClearCase/Emacs integration.
;;
;;
;; How to use
;; ==========
;;
;; 0. Make sure you're using Gnu Emacs-20.4 or later or a recent XEmacs.
;; In general it seems to work better in Gnu Emacs than in XEmacs,
;; although many XEmacs users have no problems at all with it.
;;
;; 1. Make sure that you DON'T load old versions of vc-hooks.el which contain
;; incompatible versions of the tq package (functions tq-enqueue and
;; friends). In particular, Bill Sommerfeld's VC/CC integration has this
;; problem.
;;
;; 2. Copy the files (or at least the clearcase.elc file) to a directory
;; on your emacs-load-path.
;;
;; 3. Insert this in your emacs startup file: (load "clearcase")
;;
;; When you begin editing in any view-context, a ClearCase menu will appear
;; and ClearCase Minor Mode will be activated for you.
;;
;; Summary of features
;; ===================
;;
;; Keybindings compatible with Emacs' VC (where it makes sense)
;; Richer interface than VC
;; Works on NT and Unix
;; Context sensitive menu (Emacs knows the ClearCase-status of files)
;; Snapshot view support: update, version comparisons
;; Can use Emacs Ediff for version comparison display
;; Dired Mode:
;; - en masse checkin/out etc
;; - enhanced display
;; - browse version tree
;; Completion of viewnames, version strings
;; Auto starting of views referenced as /view/TAG/.. (or \\view\TAG\...)
;; Emacs for editing comments, config specs
;; Standard ClearCase GUI tools launchable from Emacs menu
;; - version tree browser
;; - project browser
;; - UCM deliver
;; - UCM rebase
;; Operations directly available from Emacs menu/keymap:
;; create-activity
;; set-activity
;; mkelem,
;; checkout
;; checkin,
;; unco,
;; describe
;; list history
;; edit config spec
;; mkbrtype
;; snapshot view update: file, directory, view
;; version comparisons using ediff, diff or GUI
;; find checkouts
;; annotate version
;; et al.
;;
;; Acknowledgements
;; ================
;;
;; The help of the following is gratefully acknowledged:
;;
;; XEmacs support and other bugfixes:
;;
;; Rod Whitby
;; Adrian Aichner
;;
;; This was a result of examining earlier versions of VC and VC/ClearCase
;; integrations and borrowing freely therefrom. Accordingly, the following
;; are ackowledged as contributors:
;;
;; VC/ClearCase integration authors:
;;
;; Bill Sommerfeld
;; Rod Whitby
;; Andrew Markebo
;; Andy Eskilsson
;; Paul Smith
;; John Kohl
;; Chris Felaco
;;
;; VC authors:
;;
;; Eric S. Raymond
;; Andre Spiegel
;; Sebastian Kremer
;; Richard Stallman
;; Per Cederqvist
;; ttn@netcom.com
;; Andre Spiegel
;; Jonathan Stigelman
;; Steve Baur
;;
;; Other Contributors:
;;
;; Alastair Rankine
;; Andrew Maguire
;; Barnaby Dalton
;; Christian Savard
;; David O'Shea
;; Dee Zsombor
;; Gabor Zoka
;; Jason Rumney
;; Jeff Phillips
;; Justin Vallon
;; Mark Collins
;; Patrik Madison
;; Ram Bhamidipaty
;; Reinhard Hahn
;; Richard Kim
;; Richard Y. Kim
;; Simon Graham
;; Stephen Leake
;; Steven E. Harris
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;}}}
;;{{{ Version info
(defconst clearcase-version-stamp "ClearCase-version: </main/laptop/166>")
(defconst clearcase-version (substring clearcase-version-stamp 19))
(defun clearcase-maintainer-address ()
;; Avoid spam.
;;
(concat "kevin.esler.1989"
"@"
"alum.bu.edu"))
(defun clearcase-submit-bug-report ()
"Submit via mail a bug report on ClearCase Mode"
(interactive)
(and (y-or-n-p "Do you really want to submit a report on ClearCase Mode ? ")
(reporter-submit-bug-report
(clearcase-maintainer-address)
(concat "clearcase.el " clearcase-version)
'(
system-type
system-configuration
emacs-version
clearcase-clearcase-version-installed
clearcase-cleartool-path
clearcase-lt
clearcase-v3
clearcase-v4
clearcase-v5
clearcase-v6
clearcase-servers-online
clearcase-disable-tq
clearcase-on-cygwin
clearcase-setview-root
clearcase-suppress-vc-within-mvfs
shell-file-name
w32-quote-process-args
))))
;;}}}
;;{{{ Macros
(defmacro clearcase-when-debugging (&rest forms)
(list 'if 'clearcase-debug (cons 'progn forms)))
(defmacro clearcase-with-tempfile (filename-var &rest forms)
`(let ((,filename-var (clearcase-utl-tempfile-name)))
(unwind-protect
,@forms
;; Cleanup.
;;
(if (file-exists-p ,filename-var)
(delete-file ,filename-var)))))
;;}}}
;;{{{ Portability
(defvar clearcase-xemacs-p (string-match "XEmacs" emacs-version))
(defvar clearcase-on-mswindows (memq system-type
'(windows-nt ms-windows cygwin cygwin32)))
(defvar clearcase-on-cygwin (memq system-type '(cygwin cygwin32)))
(defvar clearcase-sink-file-name
(cond
(clearcase-on-cygwin "/dev/null")
(clearcase-on-mswindows "NUL")
(t "/dev/null")))
(defun clearcase-view-mode-quit (buf)
"Exit from View mode, restoring the previous window configuration."
(progn
(cond ((frame-property (selected-frame) 'clearcase-view-window-config)
(set-window-configuration
(frame-property (selected-frame) 'clearcase-view-window-config))
(set-frame-property (selected-frame) 'clearcase-view-window-config nil))
((not (one-window-p))
(delete-window)))
(kill-buffer buf)))
(defun clearcase-view-mode (arg &optional camefrom)
(if clearcase-xemacs-p
(let* ((winconfig (current-window-configuration))
(was-one-window (one-window-p))
(buffer-name (buffer-name (current-buffer)))
(clearcase-view-not-visible
(not (and (windows-of-buffer buffer-name) ;shortcut
(memq (selected-frame)
(mapcar 'window-frame
(windows-of-buffer buffer-name)))))))
(when clearcase-view-not-visible
(set-frame-property (selected-frame)
'clearcase-view-window-config winconfig))
(view-mode camefrom 'clearcase-view-mode-quit)
(setq buffer-read-only nil))
(view-mode arg)))
(defun clearcase-port-view-buffer-other-window (buffer)
(if clearcase-xemacs-p
(switch-to-buffer-other-window buffer)
(view-buffer-other-window buffer nil 'kill-buffer)))
(defun clearcase-dired-sort-by-date ()
(if (fboundp 'dired-sort-by-date)
(dired-sort-by-date)))
;; Copied from emacs-20
;;
(if (not (fboundp 'subst-char-in-string))
(defun subst-char-in-string (fromchar tochar string &optional inplace)
"Replace FROMCHAR with TOCHAR in STRING each time it occurs.
Unless optional argument INPLACE is non-nil, return a new string."
(let ((i (length string))
(newstr (if inplace string (copy-sequence string))))
(while (> i 0)
(setq i (1- i))
(if (eq (aref newstr i) fromchar)
(aset newstr i tochar)))
newstr)))
;;}}}
;;{{{ Require calls
;; nyi: we also use these at the moment:
;; -view
;; -ediff
;; -view
;; -dired-sort
(require 'cl)
(require 'comint)
(require 'dired)
(require 'easymenu)
(require 'executable)
(require 'reporter)
(require 'ring)
(or clearcase-xemacs-p
(require 'timer))
;; NT Emacs - doesn't use tq.
;;
(if (not clearcase-on-mswindows)
(require 'tq))
;;}}}
;;{{{ Debugging facilities
;; Setting this to true will enable some debug code.
;;
(defvar clearcase-debug nil)
(defun clearcase-trace (string)
(clearcase-when-debugging
(let ((trace-buf (get-buffer "*clearcase-trace*")))
(if trace-buf
(save-excursion
(set-buffer trace-buf)
(goto-char (point-max))
(insert string "\n"))))))
(defun clearcase-enable-tracing ()
(interactive)
(setq clearcase-debug t)
(get-buffer-create "*clearcase-trace*"))
(defun clearcase-disable-tracing ()
(interactive)
(setq clearcase-debug nil))
(defun clearcase-dump ()
(interactive)
(clearcase-utl-populate-and-view-buffer
"*clearcase-dump*"
nil
(function (lambda ()
(clearcase-fprop-dump-to-current-buffer)
(clearcase-vprop-dump-to-current-buffer)))))
(defun clearcase-flush-caches ()
(interactive)
(clearcase-fprop-clear-all-properties)
(clearcase-vprop-clear-all-properties))
;;}}}
;;{{{ Customizable variables
(eval-and-compile
(condition-case nil
(require 'custom)
(error nil))
(if (and (featurep 'custom)
(fboundp 'custom-declare-variable))
nil ;; We've got what we needed
;; We have the old custom-library, hack around it!
(defmacro defgroup (&rest args)
nil)
(defmacro defcustom (var value doc &rest args)
(` (defvar (, var) (, value) (, doc))))
(defmacro defface (face value doc &rest stuff)
`(make-face ,face))
(defmacro custom-declare-variable (symbol value doc &rest args)
(list 'defvar (eval symbol) value doc))))
(defgroup clearcase () "ClearCase Options" :group 'tools :prefix "clearcase")
(defcustom clearcase-keep-uncheckouts t
"When true, the contents of an undone checkout will be kept in a file
with a \".keep\" suffix. Otherwise it will be removed."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-keep-unhijacks t
"When true, the contents of an undone hijack will be kept in a file
with a \".keep\" suffix. Otherwise it will be removed."
:group 'clearcase
:type 'boolean)
;; nyi: We could also allow a value of 'prompt here
;;
(defcustom clearcase-set-to-new-activity t
"*If this variable is non-nil when a new activity is created, that activity
will be set as the current activity for the view, otherwise no change is made
to the view's current activity setting."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-prompt-for-activity-names t
"*If this variable is non-nil the user will be prompted for activity names.
Otherwise, activity names will be generated automatically and will typically
have the form \"activity011112.155233\". If the name entered is empty sucn an
internal name will also be generated."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-make-backup-files nil
"*If non-nil, backups of ClearCase files are made as with other files.
If nil (the default), files under ClearCase control don't get backups."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-complete-viewtags t
"*If non-nil, completion on viewtags is enabled. For sites with thousands of view
this should be set to nil."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-minimise-menus nil
"*If non-nil, menus will hide rather than grey-out inapplicable choices."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-auto-dired-mode t
"*If non-nil, automatically enter `clearcase-dired-mode' in dired-mode
for directories in ClearCase."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-dired-highlight t
"If non-nil, highlight reserved files in clearcase-dired buffers."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-dired-show-view t
"If non-nil, show the view tag in dired buffers."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-verify-pre-mkelem-dir-checkout nil
"*If non-nil, prompt before checking out the containing directory
before creating a new ClearCase element."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-diff-on-checkin nil
"Display diff on checkin to help you compose the checkin comment."
:group 'clearcase
:type 'boolean)
;; General customization
(defcustom clearcase-suppress-confirm nil
"If non-nil, treat user as expert; suppress yes-no prompts on some things."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-initial-mkelem-comment nil
"Prompt for initial comment when an element is created."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-command-messages nil
"Display run messages from back-end commands."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-checkin-arguments
;; For backwards compatibility with old name for this variable:
;;
(if (and (boundp 'clearcase-checkin-switches)
(not (null clearcase-checkin-switches)))
(list clearcase-checkin-switches)
nil)
"A list of extra arguments passed to the checkin command."
:group 'clearcase
:type '(repeat (string :tag "Argument")))
(defcustom clearcase-checkin-on-mkelem nil
"If t, file will be checked-in when first created as an element."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-suppress-checkout-comments nil
"Suppress prompts for checkout comments for those version control
systems which use them."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-checkout-arguments
;; For backwards compatibility with old name for this variable:
;;
(if (and (boundp 'clearcase-checkout-arguments)
(not (null clearcase-checkout-arguments)))
(list clearcase-checkout-arguments)
nil)
"A list of extra arguments passed to the checkout command."
:group 'clearcase
:type '(repeat (string :tag "Argument")))
(defcustom clearcase-directory-exclusion-list '("lost+found")
"Directory names ignored by functions that recursively walk file trees."
:group 'clearcase
:type '(repeat (string :tag "Subdirectory")))
(defcustom clearcase-use-normal-diff nil
"If non-nil, use normal diff instead of cleardiff."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-normal-diff-program "diff"
"*Program to use for generating the differential of the two files
when `clearcase-use-normal-diff' is t."
:group 'clearcase
:type 'string)
(defcustom clearcase-normal-diff-arguments
(if (and (boundp 'clearcase-normal-diff-switches)
(not (null clearcase-normal-diff-switches)))
(list clearcase-normal-diff-switches)
(list "-u"))
"A list of extra arguments passed to `clearcase-normal-diff-program'
when `clearcase-use-normal-diff' is t. Usage of the -u switch is
recommended to produce unified diffs, when your
`clearcase-normal-diff-program' supports it."
:group 'clearcase
:type '(repeat (string :tag "Argument")))
(defcustom clearcase-vxpath-glue "@@"
"The string used to construct version-extended pathnames."
:group 'clearcase
:type 'string)
(defcustom clearcase-viewroot (if clearcase-on-mswindows
"//view"
"/view")
"The ClearCase viewroot directory."
:group 'clearcase
:type 'file)
(defcustom clearcase-viewroot-drive "m:"
"The ClearCase viewroot drive letter for Windows."
:group 'clearcase
:type 'string)
(defcustom clearcase-suppress-vc-within-mvfs t
"Suppresses VC activity within the MVFS."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-hide-rebase-activities t
"Hide rebase activities from activity selection list."
:group 'clearcase
:type 'boolean)
(defcustom clearcase-rebase-id-regexp "^rebase\\."
"The regexp used to detect rebase actvities."
:group 'clearcase
:type 'string)
;;}}}
;;{{{ Global variables
;; For Emacs 24 compatibility: make sure directory-sep-char is defined.
(defconst directory-sep-char ?/)
;; Initialize clearcase-pname-sep-regexp according to
;; directory-sep-char.
(defvar clearcase-pname-sep-regexp
(format "[%s/]"
(char-to-string directory-sep-char)))
(defvar clearcase-non-pname-sep-regexp
(format "[^%s/]"
(char-to-string directory-sep-char)))
;; Matches any viewtag (without the trailing "/").
;;
(defvar clearcase-viewtag-regexp
(concat "^"
clearcase-viewroot
clearcase-pname-sep-regexp
"\\("
clearcase-non-pname-sep-regexp "*"
"\\)"
"$"
))
;; Matches ANY viewroot-relative path
;;
(defvar clearcase-vrpath-regexp
(concat "^"
clearcase-viewroot
clearcase-pname-sep-regexp
"\\("
clearcase-non-pname-sep-regexp "*"
"\\)"
))
;;}}}
;;{{{ Minor Mode: ClearCase
;; For ClearCase Minor Mode
;;
(defvar clearcase-mode nil)
(set-default 'clearcase-mode nil)
(make-variable-buffer-local 'clearcase-mode)
(put 'clearcase-mode 'permanent-local t)
;; Tell Emacs about this new kind of minor mode
;;
(if (not (assoc 'clearcase-mode minor-mode-alist))
(setq minor-mode-alist (cons '(clearcase-mode clearcase-mode)
minor-mode-alist)))
;; For now we override the bindings for VC Minor Mode with ClearCase Minor Mode
;; bindings.
;;
(defvar clearcase-mode-map (make-sparse-keymap))
(defvar clearcase-prefix-map (make-sparse-keymap))
(define-key clearcase-mode-map "\C-xv" clearcase-prefix-map)
(define-key clearcase-mode-map "\C-x\C-q" 'clearcase-toggle-read-only)
(define-key clearcase-prefix-map "b" 'clearcase-browse-vtree-current-buffer)
(define-key clearcase-prefix-map "c" 'clearcase-uncheckout-current-buffer)
(define-key clearcase-prefix-map "e" 'clearcase-edcs-edit)
(define-key clearcase-prefix-map "g" 'clearcase-annotate-current-buffer)
(define-key clearcase-prefix-map "i" 'clearcase-mkelem-current-buffer)
(define-key clearcase-prefix-map "l" 'clearcase-list-history-current-buffer)
(define-key clearcase-prefix-map "m" 'clearcase-mkbrtype)
(define-key clearcase-prefix-map "u" 'clearcase-uncheckout-current-buffer)
(define-key clearcase-prefix-map "v" 'clearcase-next-action-current-buffer)
(define-key clearcase-prefix-map "w" 'clearcase-what-rule-current-buffer)
(define-key clearcase-prefix-map "=" 'clearcase-diff-pred-current-buffer)
(define-key clearcase-prefix-map "?" 'clearcase-describe-current-buffer)
(define-key clearcase-prefix-map "~" 'clearcase-version-other-window)
;; Added by jonas054
(define-key clearcase-prefix-map "B" 'clearcase-ediff-branch-base-current-buffer)
(define-key clearcase-prefix-map "P" 'clearcase-ediff-pred-current-buffer)
;; To avoid confusion, we prevent VC Mode from being active at all by
;; undefining its keybindings for which ClearCase Mode doesn't yet have an
;; analogue.
;;
(define-key clearcase-prefix-map "a" 'undefined) ;; vc-update-change-log
(define-key clearcase-prefix-map "d" 'undefined) ;; vc-directory
(define-key clearcase-prefix-map "h" 'undefined) ;; vc-insert-headers
(define-key clearcase-prefix-map "m" 'undefined) ;; vc-merge
(define-key clearcase-prefix-map "r" 'undefined) ;; vc-retrieve-snapshot
(define-key clearcase-prefix-map "s" 'undefined) ;; vc-create-snapshot
(define-key clearcase-prefix-map "t" 'undefined) ;; vc-dired-toggle-terse-mode
;; Associate the map and the minor mode
;;
(or (not (boundp 'minor-mode-map-alist))
(assq 'clearcase-mode (symbol-value 'minor-mode-map-alist))
(setq minor-mode-map-alist
(cons (cons 'clearcase-mode clearcase-mode-map)
minor-mode-map-alist)))
(defun clearcase-mode (&optional arg)
"ClearCase Minor Mode"
(interactive "P")
;; Behave like a proper minor-mode.
;;
(setq clearcase-mode
(if (interactive-p)
(if (null arg)
(not clearcase-mode)
;; Check if the numeric arg is positive.
;;
(> (prefix-numeric-value arg) 0))
;; else
;; Use the car if it's a list.
;;
(if (consp arg)
(setq arg (car arg)))
(if (symbolp arg)
(if (null arg)
(not clearcase-mode) ;; toggle mode switch
(not (eq '- arg))) ;; True if symbol is not '-
;; else
;; assume it's a number and check that.
;;
(> arg 0))))
(if clearcase-mode
(easy-menu-add clearcase-menu 'clearcase-mode-map))
)
;;}}}
;;{{{ Minor Mode: ClearCase Dired
;;{{{ Reformatting the Dired buffer
;; Create a face for highlighting checked out files in clearcase-dired.
;;
(if (not (memq 'clearcase-dired-checkedout-face (face-list)))
(progn
(make-face 'clearcase-dired-checkedout-face)
(set-face-foreground 'clearcase-dired-checkedout-face "red")))
(defun clearcase-dired-insert-viewtag ()
(save-excursion
(progn
(goto-char (point-min))
;; Only do this if the buffer is not currently narrowed
;;
(if (= 1 (point))
(let ((viewtag (clearcase-fprop-viewtag (file-truename default-directory))))
(if viewtag
(progn
(forward-line 1)
(let ((buffer-read-only nil))
(insert (format " [ClearCase View: %s]\n" viewtag))))))))))
(defun clearcase-dired-reformat-buffer ()
"Reformats the current dired buffer."
(let* ((checkout-list nil)
(modified-file-info nil)
(hijack-list nil)
(directory default-directory)
subdir
fullpath)
;; Iterate over each line in the buffer.
;;
;; Important notes:
;; 1. In general, a Dired buffer can contain listings for several
;; directories. We pass though from top to bottom and adjust
;; subdir as we go.
;; 2. Since this is called from dired-after-reading-hook, it can get
;; called on a single-line buffer. In this case there is no subdir,
;; and no checkout-list. We need to call clearcase-fprop-checked-out
;; to test for a checkout.
;;
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(cond
;; Case 1: Look for directory markers
;;
((setq subdir (dired-get-subdir))
;; We're at a subdirectory line in the dired buffer.
;; Go and list all checkouts and hijacks in this subdirectory.
;;
(setq modified-file-info (clearcase-dired-list-modified-files subdir))
(setq checkout-list (nth 0 modified-file-info))
(setq hijack-list (nth 1 modified-file-info))
;; If no checkouts are found, we don't need to check each file, and
;; it's very slow. The checkout-list should contain something so it
;; doesn't attempt to do this.
;;
(if (null checkout-list)
(setq checkout-list '(nil)))
(if (null hijack-list)
(setq hijack-list '(nil)))
(message "Reformatting %s..." subdir))
;; Case 2: Look for files (the safest way to get the filename).
;;
((setq fullpath (dired-get-filename nil t))
;; Expand it to get rid of . and .. entries.
;;
(setq fullpath (expand-file-name fullpath))
(setq fullpath (clearcase-path-canonicalise-slashes fullpath))
;; Only modify directory listings of the correct format.
;; We replace the GID field with a checkout indicator.
;;
(if (looking-at
;; (1) (2) (3) (4)
;; -rw-rw-rw- 1 esler 5 28 Feb 2 16:02 foo.el
"..\\([drwxlts-]+ \\) *\\([0-9]+\\) \\([^ ]+\\) *\\([^ ]+ *\\) +[0-9]+\\( [^ 0-9]+ [0-9 ][0-9] .*\\)")
(let* ((replacement-begin (match-beginning 4))
(replacement-end (match-end 4))
(replacement-length (- replacement-end replacement-begin))
(checkout-replacement-text (format "CHECKOUT"))
(hijack-replacement-text (format "HIJACK"))
(is-checkout (if checkout-list
(member fullpath checkout-list)
(clearcase-fprop-checked-out fullpath)))
(is-hijack (if hijack-list
(member fullpath hijack-list)
(clearcase-fprop-hijacked fullpath))))
;; Highlight the line if the file is checked-out.
;;
(if is-checkout
(progn
;; Replace the GID field with CHECKOUT.
;;
(let ((buffer-read-only nil))
;; Pad with replacement text with trailing spaces if necessary.
;;
(if (>= replacement-length (length checkout-replacement-text))
(setq checkout-replacement-text
(concat checkout-replacement-text
(make-string (- replacement-length (length checkout-replacement-text))
32))))
(goto-char replacement-begin)
(delete-char replacement-length)
(insert (substring checkout-replacement-text 0 replacement-length)))
;; Highlight the checked out files.
;;
(if (fboundp 'put-text-property)
(let ((buffer-read-only nil))
(put-text-property replacement-begin replacement-end
'face 'clearcase-dired-checkedout-face)))
)
)
(if is-hijack
(progn
;; Replace the GID field with CHECKOUT.
;;
(let ((buffer-read-only nil))
;; Pad with replacement text with trailing spaces if necessary.
;;
(if (>= replacement-length (length hijack-replacement-text))
(setq hijack-replacement-text
(concat hijack-replacement-text
(make-string (- replacement-length (length hijack-replacement-text))
32))))
(goto-char replacement-begin)
(delete-char replacement-length)
(insert (substring hijack-replacement-text 0 replacement-length)))
;; Highlight the checked out files.
;;
(if (fboundp 'put-text-property)
(let ((buffer-read-only nil))
(put-text-property replacement-begin replacement-end
'face 'clearcase-dired-checkedout-face)))
)
)
))))
(forward-line 1))))
(message "Reformatting...Done"))
(defun clearcase-path-follow-if-vob-slink (path)
(if (clearcase-fprop-file-is-vob-slink-p path)
;; It's a slink so follow it.
;;
(let ((slink-text (clearcase-fprop-vob-slink-text path)))
(if (file-name-absolute-p slink-text)
slink-text
(concat (file-name-directory path) slink-text)))
;; Not an slink.
;;
path))
;;{{{ Searching for modified files
;;{{{ Old code
;; (defun clearcase-dired-list-checkouts (directory)
;; "Returns a list of files checked-out to the current view in DIRECTORY."
;; ;; Don't bother looking for checkouts in
;; ;; - a history-mode branch-qua-directory
;; ;; - a view-private directory
;; ;;
;; ;; NYI: For now don't run lsco in root of a snapshot because it gives errors.
;; ;; We need to make this smarter.
;; ;;
;; ;; NYI: For a pathname which is a slink to a dir, despite the fact that
;; ;; clearcase-fprop-file-is-version-p returns true, lsco fails on it,
;; ;; with "not an element". Sheesh, surely lsco ought to follow links ?
;; ;; Solution: catch the error and check if the dir is a slink then follow
;; ;; the link and retry the lsco on the target.
;; ;;
;; ;; For now just ignore the error.
;; ;;
;; (if (and (not (clearcase-vxpath-p directory))
;; (not (eq 'view-private-object (clearcase-fprop-mtype directory)))
;; (clearcase-fprop-file-is-version-p directory))
;; (let* ((ignore (message "Listing ClearCase checkouts..."))
;; (true-dir-path (file-truename directory))
;; ;; Give the directory as an argument so all names will be
;; ;; fullpaths. For some reason ClearCase adds an extra slash if you
;; ;; leave the trailing slash on the directory, so we need to remove
;; ;; it.
;; ;;
;; (native-dir-path (clearcase-path-native (directory-file-name true-dir-path)))
;; (followed-dir-path (clearcase-path-follow-if-vob-slink native-dir-path))
;; ;; Form the command:
;; ;;
;; (cmd (list
;; "lsco" "-cview" "-fmt"
;; (if clearcase-on-mswindows
;; "%n\\n"
;; "'%n\\n'")
;; followed-dir-path))
;; ;; Capture the output:
;; ;;
;; (string (clearcase-path-canonicalise-slashes
;; (apply 'clearcase-ct-cleartool-cmd cmd)))
;; ;; Split the output at the newlines:
;; ;;
;; (checkout-list (clearcase-utl-split-string-at-char string ?\n)))
;; ;; Add entries for "." and ".." if they're checked-out.
;; ;;
;; (let* ((entry ".")
;; (path (expand-file-name (concat (file-name-as-directory true-dir-path)
;; entry))))
;; (if (clearcase-fprop-checked-out path)
;; (setq checkout-list (cons path checkout-list))))
;; (let* ((entry "..")
;; (path (expand-file-name (concat (file-name-as-directory true-dir-path)
;; entry))))
;; (if (clearcase-fprop-checked-out path)
;; (setq checkout-list (cons path checkout-list))))
;; ;; If DIRECTORY is a vob-slink, checkout list will contain pathnames
;; ;; relative to the vob-slink target rather than to DIRECTORY. Convert
;; ;; them back here. We're making it appear that lsco works on
;; ;; slinks-to-dirs.
;; ;;
;; (if (clearcase-fprop-file-is-vob-slink-p true-dir-path)
;; (let ((re (regexp-quote (file-name-as-directory followed-dir-path))))
;; (setq checkout-list
;; (mapcar
;; (function
;; (lambda (path)
;; (replace-regexp-in-string re true-dir-path path)))
;; checkout-list))))
;; (message "Listing ClearCase checkouts...done")
;; ;; Return the result.
;; ;;
;; checkout-list)
;; ))
;; ;; I had believed that this implementation below OUGHT to be faster, having
;; ;; read the code in "ct+lsco". It seemed that "lsco -cview" hit the VOB and
;; ;; listed all checkouts on all elements in the directory, and then filtered by
;; ;; view. I thought it would probably be quicker to run "ct ls -vob_only" and
;; ;; keep the lines that have "[eclipsed by checkout]". However this code
;; ;; actually seemed to run slower. Leave the code here for now so I can test
;; ;; further.
;; ;;
;; (defun clearcase-dired-list-checkouts-experimental (directory)
;; "Returns a list of files checked-out to the current view in DIRECTORY."
;; ;; Don't bother looking for checkouts in a history-mode listing
;; ;; nor in view-private directories.
;; ;;
;; (if (and (not (clearcase-vxpath-p directory))
;; (not (eq 'view-private-object (clearcase-fprop-mtype directory))))
;; (let* ((ignore (message "Listing ClearCase checkouts..."))
;; (true-directory (file-truename directory))
;; ;; Move temporarily to the directory:
;; ;;
;; (default-directory true-directory)
;; ;; Form the command:
;; ;;
;; (cmd (list "ls" "-vob_only"))
;; ;; Capture the output:
;; ;;
;; (string (clearcase-path-canonicalise-slashes
;; (apply 'clearcase-ct-cleartool-cmd cmd)))
;; ;; Split the output at the newlines:
;; ;;
;; (line-list (clearcase-utl-split-string-at-char string ?\n))
;; (checkout-list nil))
;; ;; Look for lines of the form:
;; ;; FILENAME@@ [eclipsed by checkout]
;; ;;
;; (mapcar (function
;; (lambda (line)
;; (if (string-match "^\\([^ @]+\\)@@ +\\[eclipsed by checkout\\].*" line)
;; (setq checkout-list (cons (concat