-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathidlwave.el
3304 lines (3023 loc) · 117 KB
/
idlwave.el
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
;;; idlwave.el --- IDL editing mode for GNU Emacs -*- lexical-binding: t; -*-
;; Copyright (C) 1999-2024 Free Software Foundation, Inc.
;; Authors: J.D. Smith <[email protected]>
;; Carsten Dominik
;; Chris Chase
;; Maintainer: J.D. Smith <[email protected]>
;; Version: 6.5.1
;; Keywords: languages
;; This file is part of GNU Emacs.
;; GNU Emacs 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 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs 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. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; IDLWAVE enables feature-rich development and interaction with IDL,
;; the Interactive Data Language. It provides a compelling,
;; full-featured alternative to the IDLDE development environment
;; bundled with IDL.
;; See the mode description ("C-h m" in idlwave-mode or "C-h f
;; idlwave-mode") for features, key bindings, and info.
;;
;; INSTALLATION
;; ============
;;
;; Follow the instructions in the INSTALL file of the distribution.
;; In short, put this file on your load path and add the following
;; lines to your init file:
;;
;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
;;
;;
;; SOURCE
;; ======
;;
;; The newest version of IDLWAVE is available from the maintainer's
;; Webpage:
;;
;; https://github.com/jdtsmith/idlwave
;;
;; DOCUMENTATION
;; =============
;;
;; Info format documentation is available, also accessible with `M-x
;; idlwave-info'. IDLWAVE is documented online in info format. A
;; printable version of the documentation is available from the
;; maintainers webpage (see SOURCE).
;;
;;
;; ACKNOWLEDGMENTS
;; ===============
;;
;; In the remotely distant past, based on pascal.el.
;;
;; Incorporates many ideas, such as abbrevs, action routines, and
;; continuation line indenting, from wave.el, originally written by
;; Lubos Pochman, Precision Visuals, Boulder.
;;
;; Thanks to the following people for their contributions and
;; comments:
;;
;; Ulrik Dickow <dickow_at_nbi.dk>
;; Eric E. Dors <edors_at_lanl.gov>
;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
;; David Huenemoerder <dph_at_space.mit.edu>
;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
;; Dick Jackson <dick_at_d-jackson.com>
;; Xuyong Liu <liu_at_stsci.edu>
;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
;; Laurent Mugnier <mugnier_at_onera.fr>
;; Lubos Pochman <lubos_at_rsinc.com>
;; Bob Portmann <portmann_at_al.noaa.gov>
;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
;; Marty Ryba <ryba_at_ll.mit.edu>
;; Matthew Savoie <savoie_at_nsidc.org>
;; Paul Sorenson <aardvark62_at_msn.com>
;; Phil Sterne <sterne_at_dublin.llnl.gov>
;; Phil Williams <williams_at_irc.chmcc.org>
;; Nathaniel Cunningham
;;
;; CUSTOMIZATION:
;; =============
;;
;; IDLWAVE has extensive customize support; to learn about the
;; variables which control the mode's behavior, use `M-x
;; idlwave-customize'.
;;
;; You can set your own preferred values with Customize, or with Lisp
;; code in your init file. For an example of what to put into your
;; init file, check the TexInfo documentation.
;;
;; KNOWN PROBLEMS:
;; ==============
;;
;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
;; Numerics, Inc. is growing less and less complete as the two
;; languages grow increasingly apart. The mode probably shouldn't
;; even have "WAVE" in its title, but it's catchy, and was required
;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
;;
;; Moving the point backwards in conjunction with abbrev expansion
;; does not work as I would like it, but this is a problem with
;; Emacs abbrev expansion done by the self-insert-command. It ends
;; up inserting the character that expanded the abbrev after moving
;; point backward, e.g., "\cl" expanded with a space becomes
;; "LONG( )" with point before the close paren. This is solved by
;; using a temporary function in `post-command-hook' - not pretty,
;; but it works.
;;
;; Tabs and spaces are treated equally as whitespace when filling a
;; comment paragraph. To accomplish this, tabs are permanently
;; replaced by spaces in the text surrounding the paragraph, which
;; may be an undesirable side-effect. Replacing tabs with spaces is
;; limited to comments only and occurs only when a comment
;; paragraph is filled via `idlwave-fill-paragraph'.
;;
;; Determining the expression at point for printing and other
;; examination commands is somewhat rough: currently only fairly
;; simple entities are found. You can always drag-select or examine
;; a pre-selected region.
;;
;; When forcing completion of method keywords, the initial
;; query for a method has multiple entries for some methods. Would
;; be too difficult to fix this hardly used case.
;;
;;; Code:
(eval-when-compile (require 'cl-lib))
(require 'idlw-help)
(require 'idlw-variables)
(require 'idlw-routine)
(require 'idlw-complete)
(require 'idlw-bindings)
(require 'idlw-menus)
(require 'idlw-scan)
(declare-function idlwave-shell-get-path-info "idlw-shell")
(declare-function idlwave-shell-temp-file "idlw-shell")
(declare-function idlwave-shell-is-running "idlw-shell")
(declare-function widget-value "wid-edit" (widget))
(declare-function comint-dynamic-complete-filename "comint" ())
;;----------------------------------------------------
;; Loading/Initialization
(defvar imenu-create-index-function)
(defvar imenu-extract-index-name-function)
(defvar imenu-prev-index-position-function)
(defconst idlwave-mode-version
(if (fboundp 'package-get-version)
(package-get-version)
"6.5.0"))
;;;###autoload
(define-derived-mode idlwave-mode prog-mode "IDLWAVE"
"Major mode for editing IDL source files.
The main features of this mode are
1. Indentation and Formatting
--------------------------
Like other Emacs programming modes, C-j inserts a newline and indents.
TAB is used for explicit indentation of the current line.
To start a continuation line, use \\[idlwave-split-line]. This
function can also be used in the middle of a line to split the line
at that point. When used inside a long constant string, the string
is split at that point with the `+' concatenation operator.
Comments are indented as follows:
`;;;' Indentation remains unchanged.
`;;' Indent like the surrounding code
`;' Indent to a minimum column.
The indentation of comments starting in column 0 is never changed.
Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
comment. The indentation of the second line of the paragraph
relative to the first will be retained. Use
\\[auto-fill-mode] to toggle auto-fill mode for these
comments. When the variable `idlwave-fill-comment-line-only' is
nil, code can also be auto-filled and auto-indented.
To convert pre-existing IDL code to your formatting style, mark the
entire buffer with \\[mark-whole-buffer] and execute
\\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
again followed by \\[indent-region] (`indent-region').
2. Routine Info
------------
IDLWAVE displays information about the calling sequence and the
accepted keyword parameters of a procedure or function with
\\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
source file of a module. These commands know about system
routines, all routines in idlwave-mode buffers and (when the
idlwave-shell is active) about all modules currently compiled under
this shell. It also makes use of pre-compiled or custom-scanned
user and library catalogs many popular libraries ship with by
default. Use \\[idlwave-update-routine-info] to update this
information, which is also used for completion (see item 4).
3. Online IDL Help
---------------
\\[idlwave-context-help] displays the IDL documentation relevant
for the system variable, keyword, or routines at point. A single
key stroke gets you directly to the right place in the docs. See
the manual to configure where and how the HTML help is displayed.
4. Completion
----------
\\[idlwave-complete] completes the names of procedures, functions
class names, keyword parameters, system variables and tags, class
tags, structure tags, filenames and much more. It is context
sensitive and figures out what is expected at point. Lower case
strings are completed in lower case, other strings in mixed or
upper case.
5. Code Templates and Abbreviations
--------------------------------
Many Abbreviations are predefined to expand to code fragments and templates.
The abbreviations start generally with a `\\'. Some examples:
\\pr PROCEDURE template
\\fu FUNCTION template
\\c CASE statement template
\\sw SWITCH statement template
\\f FOR loop template
\\r REPEAT Loop template
\\w WHILE loop template
\\i IF statement template
\\elif IF-ELSE statement template
\\b BEGIN
For a full list, use \\[idlwave-list-abbrevs]. Some templates also
have direct keybindings - see the list of keybindings below.
\\[idlwave-doc-header] inserts a documentation header at the
beginning of the current program unit (pro, function or main).
Change log entries can be added to the current program unit with
\\[idlwave-doc-modification].
6. Automatic Case Conversion
-------------------------
The case of reserved words and some abbrevs is controlled by
`idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
7. Automatic END completion
------------------------
If the variable `idlwave-expand-generic-end' is non-nil, each END typed
will be converted to the specific version, like ENDIF, ENDFOR, etc.
8. Hooks
-----
Turning on `idlwave-mode' runs `idlwave-mode-hook'.
9. Documentation and Customization
-------------------------------
Info documentation for this package is available. Use
\\[idlwave-info] to display (complain to your sysadmin if that does
not work). For Postscript, PDF, and HTML versions of the
documentation, check IDLWAVE's website at URL
`https://github.com/jdtsmith/idlwave'.
IDLWAVE has customize support - see the group `idlwave'.
10.Keybindings
-----------
Here is a list of all keybindings of this mode.
If some of the key bindings below show with ??, use \\[describe-key]
followed by the key sequence to see what the key sequence does.
\\{idlwave-mode-map}"
:abbrev-table idlwave-mode-abbrev-table
(if idlwave-startup-message
(message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
(setq idlwave-startup-message nil)
(set (make-local-variable 'indent-line-function) #'idlwave-indent-and-action)
(set (make-local-variable idlwave-comment-indent-function)
#'idlwave-comment-hook)
(set (make-local-variable 'comment-start-skip) ";+[ \t]*")
(set (make-local-variable 'comment-start) ";")
(set (make-local-variable 'comment-add) 1) ; ";;" for new and regions
(set (make-local-variable 'abbrev-all-caps) t)
(set (make-local-variable 'indent-tabs-mode) nil)
(set (make-local-variable 'completion-ignore-case) t)
(setq abbrev-mode t)
(set (make-local-variable 'normal-auto-fill-function) #'idlwave-auto-fill)
(setq comment-end "")
(set (make-local-variable 'comment-multi-line) nil)
(set (make-local-variable 'paragraph-separate)
"[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
(set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
(set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
(set (make-local-variable 'parse-sexp-ignore-comments) t)
;; ChangeLog
(set (make-local-variable 'add-log-current-defun-function)
#'idlwave-current-routine-fullname)
;; Set tag table list to use IDLTAGS as file name.
(if (boundp 'tag-table-alist)
(add-to-list 'tag-table-alist '("\\.pro\\'" . "IDLTAGS")))
;; Font-lock additions
(set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
(set (make-local-variable 'font-lock-mark-block-function)
#'idlwave-mark-subprogram)
(set (make-local-variable 'font-lock-fontify-region-function)
#'idlwave-font-lock-fontify-region)
;; Imenu setup
;; (set (make-local-variable 'imenu-create-index-function)
;; ;; FIXME: Why set it explicitly to the value it already has?
;; 'imenu-default-create-index-function)
(set (make-local-variable 'imenu-extract-index-name-function)
#'idlwave-unit-name)
(set (make-local-variable 'imenu-prev-index-position-function)
#'idlwave-prev-index-position)
;; defun movement
(set (make-local-variable 'beginning-of-defun-function)
#'idlwave-beginning-of-subprogram)
(set (make-local-variable 'end-of-defun-function)
#'idlwave-end-of-subprogram)
;; HideShow setup
(add-to-list 'hs-special-modes-alist
(list 'idlwave-mode
idlwave-begin-block-reg
idlwave-end-block-reg
";"
'idlwave-forward-block nil))
;; Make a local post-command-hook and add our hook to it
(add-hook 'post-command-hook #'idlwave-command-hook nil 'local)
;; Make local hooks for buffer updates
(add-hook 'kill-buffer-hook #'idlwave-kill-buffer-update nil 'local)
(add-hook 'after-save-hook #'idlwave-save-buffer-update nil 'local)
(add-hook 'after-save-hook #'idlwave-revoke-license-to-kill nil 'local)
;; Setup directories and file, if necessary
(idlwave-setup)
;; Update the routine info with info about current buffer?
(idlwave-new-buffer-update))
;; Special module
(if idlwave-complete-structure-tags
;; FIXME: This `require' causes a cyclic load during byte-compilation.
nil ;; (require 'idlw-complete-structtag)
)
;;;###autoload
(add-to-list 'auto-mode-alist (cons (purecopy "\\.pro\\'") 'idlwave-mode))
(declare-function speedbar-add-supported-extension "speedbar" (extension))
(with-eval-after-load "speedbar" (speedbar-add-supported-extension ".pro"))
(defvar idlwave--command-function nil
"If non-nil, a function called from `post-command-hook'.
It is evaluated in the Lisp function `idlwave-command-hook' which is
placed in `post-command-hook'.")
(defun idlwave-command-hook ()
"Command run after every command.
Evaluates a non-nil value of the *variable* `idlwave--command-function' and
sets the variable to zero afterwards."
(and idlwave--command-function
(with-demoted-errors "idlwave-command-hook: %S"
(funcall (prog1 idlwave--command-function
(setq idlwave--command-function nil))))))
(defvar idlwave-setup-done nil)
(defun idlwave-setup ()
"Setup directories, files, and path locations for IDLWAVE."
(unless idlwave-setup-done
(if (not (file-directory-p idlwave-config-directory))
(make-directory idlwave-config-directory))
(setq
idlwave-user-catalog-file (expand-file-name
idlwave-user-catalog-file
idlwave-config-directory)
idlwave-xml-system-rinfo-converted-file
(expand-file-name
idlwave-xml-system-rinfo-converted-file
idlwave-config-directory)
idlwave-path-file (expand-file-name
idlwave-path-file
idlwave-config-directory))
;; Check and setup help location
(idlwave-read-paths) ; we may need these early
(idlwave-help-check-locations)
(setq idlwave-setup-done t)))
;;----------------------------------------------------
;; Fontification
;;
(defun idlwave-font-lock-fontify-region (beg end &optional verbose)
"Fontify continuation lines correctly."
(let (pos)
(save-excursion
(goto-char beg)
(forward-line -1)
(when (setq pos (idlwave-is-continuation-line))
(goto-char pos)
(idlwave-beginning-of-statement)
(setq beg (point)))))
(font-lock-default-fontify-region beg end verbose))
;;----------------------------------------------------
;; Begin/end blocks
(defun idlwave-block-master ()
"Define block begin and end delimiters."
(let ((case-fold-search t))
(save-excursion
(cond
((looking-at "pro\\|case\\|switch\\|function\\>")
(assoc (downcase (match-string 0)) idlwave-block-matches))
((looking-at "begin\\>")
(let ((limit (save-excursion
(idlwave-beginning-of-statement)
(point))))
(cond
((re-search-backward ":[ \t]*\\=" limit t)
;; seems to be a case thing
'("begin" . "end"))
((re-search-backward idlwave-block-match-regexp limit t)
(assoc (downcase (match-string 1))
idlwave-block-matches))
(t
;; Just a normal block
'("begin" . "end")))))
(t nil)))))
(defun idlwave-close-block ()
"Terminate the current block with the correct END statement."
(interactive)
;; Start new line if we are not in a new line
(unless (save-excursion
(skip-chars-backward " \t")
(bolp))
(let ((idlwave-show-block nil))
(newline-and-indent)))
(let ((last-abbrev-location (point))) ; for upcasing
(insert "end")
(idlwave-show-begin)))
(defun idlwave-backward-up-block (&optional arg)
"Move to beginning of enclosing block if prefix ARG >= 0.
If prefix ARG < 0 then move forward to enclosing block end."
(interactive "p")
(idlwave-block-jump-out (- arg) 'nomark))
(defun idlwave-beginning-of-block ()
"Go to the beginning of the current block."
(interactive)
(idlwave-block-jump-out -1 'nomark)
(forward-word-strictly 1))
(defun idlwave-end-of-block ()
"Go to the beginning of the current block."
(interactive)
(idlwave-block-jump-out 1 'nomark)
(backward-word-strictly 1))
(defun idlwave-forward-block (&optional arg)
"Move across next nested block."
(interactive)
(let ((arg (or arg 1)))
(if (idlwave-down-block arg)
(idlwave-block-jump-out arg 'nomark))))
(defun idlwave-backward-block ()
"Move backward across previous nested block."
(interactive)
(if (idlwave-down-block -1)
(idlwave-block-jump-out -1 'nomark)))
(defun idlwave-down-block (&optional arg)
"Go down a block.
With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
Returns non-nil if successful."
(interactive "p")
(let (status)
(if (< arg 0)
;; Backward
(let ((eos (save-excursion
(idlwave-block-jump-out -1 'nomark)
(point))))
(if (setq status (idlwave-find-key
idlwave-end-block-reg -1 'nomark eos))
(idlwave-beginning-of-statement)
(message "No nested block before beginning of containing block.")))
;; Forward
(let ((eos (save-excursion
(idlwave-block-jump-out 1 'nomark)
(point))))
(if (setq status (idlwave-find-key
idlwave-begin-block-reg 1 'nomark eos))
(idlwave-end-of-statement)
(message "No nested block before end of containing block."))))
status))
(defun idlwave-block-jump-out (&optional dir nomark)
"When optional argument DIR is non-negative, move forward to end of
current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
regular expressions. When DIR is negative, move backwards to block beginning.
Recursively calls itself to skip over nested blocks. DIR defaults to
forward. Calls `push-mark' unless the optional argument NOMARK is
non-nil. Movement is limited by the start of program units because of
possibility of unbalanced blocks."
(interactive "P")
(or dir (setq dir 0))
(let* ((here (point))
(case-fold-search t)
(limit (if (>= dir 0) (point-max) (point-min)))
(block-limit (if (>= dir 0)
idlwave-begin-block-reg
idlwave-end-block-reg))
found
(block-reg (concat idlwave-begin-block-reg "\\|"
idlwave-end-block-reg))
(unit-limit (or (save-excursion
(if (< dir 0)
(idlwave-find-key
idlwave-begin-unit-reg dir t limit)
(end-of-line)
(idlwave-find-key
idlwave-end-unit-reg dir t limit)))
limit)))
(if (>= dir 0) (end-of-line)) ;Make sure we are in current block
(if (setq found (idlwave-find-key block-reg dir t unit-limit))
(while (and found (looking-at block-limit))
(if (>= dir 0) (forward-word-strictly 1))
(idlwave-block-jump-out dir t)
(setq found (idlwave-find-key block-reg dir t unit-limit))))
(if (not nomark) (push-mark here))
(if (not found) (goto-char unit-limit)
(if (>= dir 0) (forward-word-strictly 1)))))
(defun idlwave-show-begin-check ()
"Ensure that the previous word was a token before `idlwave-show-begin'.
An END token must be preceded by whitespace."
(if
(save-excursion
(backward-word-strictly 1)
(backward-char 1)
(looking-at "[ \t\n\f]"))
(idlwave-show-begin)))
(defun idlwave-show-begin ()
"Find the start of current block and blinks to it for a second.
Also checks if the correct END statement has been used."
;; All end statements are reserved words
;; Re-indent end line
;;(insert-char ?\ 1) ;; So indent, etc. work well
;;(backward-char 1)
(let* ((pos (point-marker))
(last-abbrev-marker (copy-marker last-abbrev-location))
(eol-pos (line-end-position))
begin-pos end-pos end end1 )
(if idlwave-reindent-end (idlwave-indent-line))
(setq last-abbrev-location (marker-position last-abbrev-marker))
(when (and (idlwave-modify-abbrev 0 t)
idlwave-show-block)
(save-excursion
;; Move inside current block
(goto-char last-abbrev-marker)
(idlwave-block-jump-out -1 'nomark)
(setq begin-pos (point))
(idlwave-block-jump-out 1 'nomark)
(setq end-pos (point))
(if (> end-pos eol-pos)
(setq end-pos pos))
(goto-char end-pos)
(setq end (buffer-substring
(progn
(skip-chars-backward "a-zA-Z")
(point))
end-pos))
(goto-char begin-pos)
(when (setq end1 (cdr (idlwave-block-master)))
(cond
((null end1)) ; no-operation
((string= (downcase end) (downcase end1))
(sit-for 0.75))
((string= (downcase end) "end")
;; A generic end
(if idlwave-expand-generic-end
(save-excursion
(goto-char pos)
(backward-char 3)
(insert (if (string= end "END") (upcase end1) end1))
(delete-char 3)))
(sit-for 1))
(t
(beep)
(message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
end1 end)
(sit-for 1))))))))
(defun idlwave-mark-block ()
"Mark containing block."
(interactive)
(idlwave-end-of-statement)
(idlwave-backward-up-block -1)
(idlwave-end-of-statement)
(let ((end (point)))
(idlwave-backward-block)
(idlwave-beginning-of-statement)
(push-mark end nil t)))
;;----------------------------------------------------
;; Routines/Subprograms
(defun idlwave-beginning-of-subprogram (&optional nomark)
"Move point to the beginning of the current program unit.
If NOMARK is non-nil, do not push mark."
(interactive)
(idlwave-find-key idlwave-begin-unit-reg -1 nomark))
(defun idlwave-end-of-subprogram (&optional nomark)
"Move point to the start of the next program unit.
If NOMARK is non-nil, do not push mark."
(interactive)
(idlwave-end-of-statement)
(idlwave-find-key idlwave-end-unit-reg 1 nomark))
(defun idlwave-mark-subprogram ()
"Put mark at beginning of program, point at end.
The marks are pushed."
(interactive)
(idlwave-end-of-statement)
(idlwave-beginning-of-subprogram)
(let ((beg (point)))
(idlwave-forward-block)
(push-mark beg nil t))
(exchange-point-and-mark))
(defun idlwave-current-routine-fullname ()
(idlwave-make-full-name (idlwave-current-routine)))
(defun idlwave-current-routine ()
"Return (NAME TYPE CLASS) of current routine."
(idlwave-routines)
(save-excursion
(idlwave-beginning-of-subprogram 'nomark)
(if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
(let* ((type (if (string= (downcase (match-string 1)) "pro")
'pro 'function))
(class (idlwave-sintern-class (match-string 3)))
(name (idlwave-sintern-routine-or-method (match-string 4) class)))
(list name type class)))))
(defvar idlwave-force-class-query nil)
(defun idlwave-resolve (&optional arg)
"Call RESOLVE_ROUTINE on the module name at point.
Like `idlwave-routine-info', this looks for a routine call at point.
After confirmation in the minibuffer, it will use the shell to issue
a RESOLVE call for this routine, to attempt to make it defined and its
routine info available for IDLWAVE. If the routine is a method call,
both `class__method' and `class__define' will be tried.
With ARG, enforce query for the class of object methods."
(interactive "P")
(let* ((idlwave-query-class nil)
(idlwave-force-class-query (equal arg '(4)))
(module (idlwave-what-module))
(name (idlwave-make-full-name module))
(type (if (eq (nth 1 module) 'pro) "pro" "function"))
(resolve (read-string "Resolve: " (format "%s %s" type name)))
(kwd "")
class)
(if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
resolve)
(setq type (match-string 1 resolve)
class (if (match-beginning 2)
(match-string 3 resolve)
nil)
name (match-string 4 resolve)))
(if (string= (downcase type) "function")
(setq kwd ",/is_function"))
(cond
((null class)
(idlwave-shell-send-command
(format "resolve_routine,'%s'%s" (downcase name) kwd)
#'idlwave-update-routine-info
nil t))
(t
(idlwave-shell-send-command
(format "resolve_routine,'%s__define'%s" (downcase class) kwd)
(lambda ()
(idlwave-shell-send-command
(format "resolve_routine,'%s__%s'%s"
(downcase class) (downcase name) kwd)
#'idlwave-update-routine-info
nil t)))))))
;;----------------------------------------------------
;; Statements/substatements
(defun idlwave-mark-statement ()
"Mark current IDL statement."
(interactive)
(idlwave-end-of-statement)
(let ((end (point)))
(idlwave-beginning-of-statement)
(push-mark end nil t)))
(defvar idlwave-shell-prompt-pattern)
(defun idlwave-beginning-of-statement ()
"Move to beginning of the current statement.
Skips back past statement continuations.
Point is placed at the beginning of the line whether or not this is an
actual statement."
(interactive)
(cond
((derived-mode-p 'idlwave-shell-mode)
(if (re-search-backward idlwave-shell-prompt-pattern nil t)
(goto-char (match-end 0))))
(t
(if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
(idlwave-previous-statement)
(beginning-of-line)))))
(defun idlwave-previous-statement ()
"Move point to beginning of the previous statement.
Returns t if the current line before moving is the beginning of
the first non-comment statement in the file, and nil otherwise."
(interactive)
(let (first-statement)
(if (not (= (forward-line -1) 0))
;; first line in file
t
;; skip blank lines, label lines, include lines and line comments
(while (and
;; The current statement is the first statement until we
;; reach another statement.
(setq first-statement
(or
(looking-at idlwave-comment-line-start-skip)
(looking-at "[ \t]*$")
(looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
(looking-at "^@")))
(= (forward-line -1) 0)))
;; skip continuation lines
(while (and
(save-excursion
(forward-line -1)
(idlwave-is-continuation-line))
(= (forward-line -1) 0)))
first-statement)))
(defun idlwave-end-of-statement ()
"Move point to the end of the current IDL statement.
If not in a statement just moves to end of line. Returns position."
(interactive)
(while (and (idlwave-is-continuation-line)
(= (forward-line 1) 0))
(while (and (idlwave-is-comment-or-empty-line)
(= (forward-line 1) 0))))
(end-of-line)
(point))
(defun idlwave-end-of-statement0 ()
"Move point to the end of the current IDL statement.
If not in a statement just moves to end of line. Returns position."
(interactive)
(while (and (idlwave-is-continuation-line)
(= (forward-line 1) 0)))
(end-of-line)
(point))
(defun idlwave-next-statement (&optional eos)
"Move point to beginning of the next IDL statement.
Returns t if that statement is the last non-comment IDL statement
in the file, and nil otherwise."
(interactive)
(let (last-statement)
(if eos (goto-char eos) (idlwave-end-of-statement))
;; skip blank lines, label lines, include lines and line comments
(while (and (= (forward-line 1) 0)
;; The current statement is the last statement until
;; we reach a new statement.
(setq last-statement
(or
(looking-at idlwave-comment-line-start-skip)
(looking-at "[ \t]*$")
(looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
(looking-at "^@")))))
last-statement))
(defun idlwave-skip-label-or-case (&optional eos)
"Skip label or case statement element.
Returns position after label.
If there is no label point is not moved and nil is returned."
;; Case expressions and labels are terminated by a colon.
;; So we find the first colon in the line and make sure
;; - no `?' is before it (might be a ? b : c)
;; - it is not in a comment
;; - not in a string constant
;; - not in parenthesis (like a[0:3])
;; - not followed by another ":" in explicit class, ala a->b::c
;; As many in this mode, this function is heuristic and not an exact
;; parser.
(let* ((start (point))
(eos (or eos (save-excursion (idlwave-end-of-statement) (point))))
(end (idlwave-find-key ":" 1 'nomark eos)))
(if (and end
(= (nth 0 (parse-partial-sexp start end)) 0)
(not (string-match "\\?" (buffer-substring start end)))
(not (string-match "^::" (buffer-substring end eos))))
(progn
(forward-char)
(point))
(goto-char start)
nil)))
(defun idlwave-start-of-substatement (&optional pre)
"Move to start of next IDL substatement after point.
Uses the type of the current IDL statement to determine if the next
statement is on a new line or is a subpart of the current statement.
Returns point at start of substatement modulo whitespace.
If optional argument is non-nil move to beginning of current
substatement."
(let ((orig (point))
(eos (save-excursion (idlwave-end-of-statement) (point)))
(ifnest 0)
st nst last)
(idlwave-beginning-of-statement)
(setq last (point))
(idlwave-skip-label-or-case eos)
(if (and pre (> (point) orig)) ;; Previous statement isn't beyond point!
(goto-char last))
(if (< (point) orig)
(idlwave-skip-multi-commands orig))
(setq last (point))
;; Continue looking for substatements until we are past orig
(while (and (<= (point) orig) (not (eobp)))
(setq last (point))
(setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
(if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
(cond ((and nst
(idlwave-find-key nst 1 'nomark eos))
(goto-char (match-end 0)))
((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
(setq ifnest (1- ifnest))
(goto-char (match-end 0)))
(t (setq ifnest 0)
(idlwave-next-statement eos))))
(if pre (goto-char last))
;; If a continuation line starts here, move to next line
(when (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
(beginning-of-line 2))
(while
(and (not (eobp))
(or (looking-at idlwave-comment-line-start-skip) ;comment only
(looking-at "[ \t]*$"))) ; blank
(beginning-of-line 2))
(point)))
(defun idlwave-prev-index-position ()
"Search for the previous procedure or function.
Return nil if not found. For use with imenu.el."
(save-match-data
(cond
((idlwave-find-key idlwave-profun-reg -1 'nomark))
(t nil))))
(defun idlwave-unit-name ()
"Return the unit name.
Assumes that point is at the beginning of the unit as found by
`idlwave-prev-index-position'."
(forward-sexp 2)
(forward-sexp -1)
(let ((begin (point)))
(re-search-forward
"[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
(buffer-substring-no-properties begin (point))))
;;----------------------------------------------------
;; Comments/strings
(defun idlwave-comment-hook ()
"Compute indent for the beginning of the IDL comment delimiter."
(if (or (looking-at idlwave-no-change-comment)
(looking-at (or idlwave-begin-line-comment "^;")))
(current-column)
(if (looking-at idlwave-code-comment)
(if (save-excursion (skip-chars-backward " \t") (bolp))
;; On line by itself, indent as code
(let ((tem (idlwave-calculate-indent)))
(if (listp tem) (car tem) tem))
;; after code - do not change
(current-column))
(skip-chars-backward " \t")
(max (if (bolp) 0 (1+ (current-column)))
comment-column))))
(defun idlwave-toggle-comment-region (beg end &optional n)
"Comment the lines in the region if the first non-blank line is
commented, and conversely, uncomment region. If optional prefix arg
N is non-nil, then for N positive, add N comment delimiters or for N
negative, remove N comment delimiters.
Uses `comment-region' which does not place comment delimiters on
blank lines."
(interactive "r\nP")
(if n
(comment-region beg end (prefix-numeric-value n))
(save-excursion
(goto-char beg)
(beginning-of-line)
;; skip blank lines
(skip-chars-forward " \t\n")
(if (looking-at (concat "[ \t]*\\(" comment-start "+\\)"))
(uncomment-region beg end)
(comment-region beg end)))))
(defun idlwave-skip-multi-commands (&optional lim)
"Skip past multiple commands on a line (or multiple lines) (with `&')."
(let ((save-point (point)))
(while (re-search-forward "\\s-\\(&\\)[^&]" lim t)
(backward-char)
(if (and (not (idlwave-quoted))
(not (eq (char-before (- (point) 1)) ?&)))
(setq save-point (point))))
(goto-char save-point)
save-point))
(defun idlwave-goto-comment ()
"Move to start of comment delimiter on current line.
Moves to end of line if there is no comment delimiter.
Ignores comment delimiters in strings.
Returns point if comment found and nil otherwise."
(let ((eos (line-end-position))
(data (match-data))
found)
;; Look for first comment delimiter not in a string
(beginning-of-line)
(setq found (search-forward comment-start eos 'lim))
(while (and found (idlwave-in-quote))
(setq found (search-forward comment-start eos 'lim)))
(store-match-data data)
(and found (not (idlwave-in-quote))
(progn
(backward-char 1)
(point)))))
(defun idlwave-commented-paragraph-beg-end ()
"Find and return the beginning and end position of a commented paragraph.
End is calculated as distance from end of buffer, to accommodate
additions from filling."
(let (pre fill-prefix-reg bcl start end) ;; diff
(beginning-of-line)
(setq bcl (point))
(re-search-forward (concat "^[ \t]*" comment-start "+")
(line-end-position) t)
;; Get the comment leader on the line and its length
(setq pre (current-column))
;; the comment leader is the indentation plus exactly the
;; number of consecutive ";".
(setq fill-prefix-reg
(concat
(setq fill-prefix
(regexp-quote (buffer-substring (line-beginning-position)
(point))))
"[^;]"))
;; Mark the beginning and end of the paragraph
(goto-char bcl)
(while (and (looking-at fill-prefix-reg)