File: bookmark.sl

package info (click to toggle)
jed 0.98.7-14
  • links: PTS
  • area: main
  • in suites: slink
  • size: 3,088 kB
  • ctags: 3,851
  • sloc: ansic: 29,315; makefile: 257; sh: 248
file content (81 lines) | stat: -rw-r--r-- 1,649 bytes parent folder | download | duplicates (2)
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
% These routines user 'user_marks' to implement book marks.  A book mark 
% may be placed in any buffer and returning to the mark may cause a change
% of buffer.

% The only functions that are considered external are 'bkmrk_set_mark'
% and 'bkmrk_goto_mark'.  These functions prompt for a a key '0' - '9'
% or a SPACE.


variable Book_Marks = Mark_Type [10];
variable Bkmrk_Last_Position = NULL;

define bkmrk_get_or_set_mark (get)
{
   variable n;
   variable prompt;
   variable m;
   
   if ((Bkmrk_Last_Position != NULL) and get)
     get = 2;

   prompt = "Bookmark number:";
   if (get == 2)
     prompt = "Bookmark number or SPACE for last position:";
   
   flush (prompt);
   n = getkey ();
   
   if ((get == 2) and (n == ' '))
     return Bkmrk_Last_Position;

   n -= '0';

   if ((n < 0) or (n > 9)) error ("Number must be less than 10");
   
   if (get)
     return Book_Marks[n];

   Book_Marks[n] = create_user_mark ();
   vmessage ("Bookmark %d set.", n);
}

define bkmrk_set_mark ()
{
   bkmrk_get_or_set_mark (0);
}

define bkmrk_goto_mark ()
{
   variable mrk = bkmrk_get_or_set_mark (1);

   if (mrk == NULL)
     error ("Bookmark has not been set");
   

   Bkmrk_Last_Position = create_user_mark ();

   sw2buf (user_mark_buffer (mrk));
   !if (is_user_mark_in_narrow (mrk))
     {
#ifdef HAS_BLOCAL_VAR
	variable fun;
	ERROR_BLOCK
	  {
	     _clear_error ();
	     error ("Mark lies outside visible part of buffer.");
	  }
	fun = get_blocal_var ("bookmark_narrow_hook");
	mrk; eval (fun);
#else
	error ("Mark lies outside visible part of buffer.");
#endif
     }
   

   goto_user_mark (mrk);
   message ("done");
}