2 * Copyright (C) 1984-2015 Mark Nudelman
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
7 * For more information, see the README file.
13 extern IFILE curr_ifile;
15 extern int jump_sline;
19 * Each mark is identified by a lowercase or uppercase letter.
20 * The final one is lmark, for the "last mark"; addressed by the apostrophe.
22 #define NMARKS ((2*26)+1) /* a-z, A-Z, lastmark */
23 #define LASTMARK (NMARKS-1)
24 static struct mark marks[NMARKS];
27 * Initialize the mark table to show no marks are set.
34 for (i = 0; i < NMARKS; i++)
35 marks[i].m_scrpos.pos = NULL_POSITION;
39 * See if a mark letter is valid (between a and z).
44 if (c >= 'a' && c <= 'z')
45 return (&marks[c-'a']);
47 if (c >= 'A' && c <= 'Z')
48 return (&marks[c-'A'+26]);
50 error("Invalid mark letter", NULL_PARG);
55 * Get the mark structure identified by a character.
56 * The mark struct may come either from the mark table
57 * or may be constructed on the fly for certain characters like ^, $.
63 static struct mark sm;
69 * Beginning of the current file.
72 m->m_scrpos.pos = ch_zero();
74 m->m_ifile = curr_ifile;
78 * End of the current file.
82 error("Cannot seek to end of file", NULL_PARG);
86 m->m_scrpos.pos = ch_tell();
87 m->m_scrpos.ln = sc_height-1;
88 m->m_ifile = curr_ifile;
92 * Current position in the current file.
95 get_scrpos(&m->m_scrpos);
96 m->m_ifile = curr_ifile;
102 m = &marks[LASTMARK];
106 * Must be a user-defined mark.
111 if (m->m_scrpos.pos == NULL_POSITION)
113 error("Mark not set", NULL_PARG);
122 * Is a mark letter is invalid?
127 return (getmark(c) == NULL);
131 * Set a user-defined mark.
137 struct scrpos scrpos;
143 m->m_scrpos = scrpos;
144 m->m_ifile = curr_ifile;
148 * Set lmark (the mark named by the apostrophe).
153 struct scrpos scrpos;
155 if (ch_getflags() & CH_HELPFILE)
158 if (scrpos.pos == NULL_POSITION)
160 marks[LASTMARK].m_scrpos = scrpos;
161 marks[LASTMARK].m_ifile = curr_ifile;
171 struct scrpos scrpos;
178 * If we're trying to go to the lastmark and
179 * it has not been set to anything yet,
180 * set it to the beginning of the current file.
182 if (m == &marks[LASTMARK] && m->m_scrpos.pos == NULL_POSITION)
184 m->m_ifile = curr_ifile;
185 m->m_scrpos.pos = ch_zero();
186 m->m_scrpos.ln = jump_sline;
190 * If we're using lmark, we must save the screen position now,
191 * because if we call edit_ifile() below, lmark will change.
192 * (We save the screen position even if we're not using lmark.)
194 scrpos = m->m_scrpos;
195 if (m->m_ifile != curr_ifile)
198 * Not in the current file; edit the correct file.
200 if (edit_ifile(m->m_ifile))
204 jump_loc(scrpos.pos, scrpos.ln);
208 * Return the position associated with a given mark letter.
210 * We don't return which screen line the position
211 * is associated with, but this doesn't matter much,
212 * because it's always the first non-blank line on the screen.
221 return (NULL_POSITION);
223 if (m->m_ifile != curr_ifile)
225 error("Mark not in current file", NULL_PARG);
226 return (NULL_POSITION);
228 return (m->m_scrpos.pos);
232 * Clear the marks associated with a specified ifile.
239 for (i = 0; i < NMARKS; i++)
240 if (marks[i].m_ifile == ifile)
241 marks[i].m_scrpos.pos = NULL_POSITION;