File: bookmark.sl

package info (click to toggle)
jed 1%3A0.99.19-7
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 5,368 kB
  • ctags: 5,809
  • sloc: ansic: 48,117; sh: 2,977; makefile: 518
file content (77 lines) | stat: -rw-r--r-- 1,658 bytes parent folder | download | duplicates (5)
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
% 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.


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

private 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:";
   
   n = get_mini_response (prompt);
   
   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 (mrk.buffer_name);
   !if (is_user_mark_in_narrow (mrk))
     {
#ifdef HAS_BLOCAL_VAR
	variable fun;
	try
	  {
	     fun = get_blocal_var ("bookmark_narrow_hook");
	     mrk; eval (fun);
	  }
	catch AnyError:
	  throw UsageError, "Mark lies outside visible part of buffer.";
#else
	error ("Mark lies outside visible part of buffer.");
#endif
     }
   

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