Mercurial > emacs
annotate lisp/textmodes/scribe.el @ 1717:aa7d6d57504b
* frame.h (struct frame): New fields `can_have_scrollbars' and
`has_vertical_scrollbars'.
(FRAME_CAN_HAVE_SCROLLBARS, FRAME_HAS_VERTICAL_SCROLLBARS): New
accessors, for both the MULTI_FRAME and non-MULTI_FRAME.
(VERTICAL_SCROLLBAR_WIDTH, WINDOW_VERTICAL_SCROLLBAR,
WINDOW_VERTICAL_SCROLLBAR_COLUMN,
WINDOW_VERTICAL_SCROLLBAR_HEIGHT): New macros.
* window.h (struct window): New field `vertical_scrollbar'.
* xterm.h (struct x_display): vertical_scrollbars,
judge_timestamp, vertical_scrollbar_extra: New fields.
(struct scrollbar): New struct.
(VERTICAL_SCROLLBAR_PIXEL_WIDTH, VERTICAL_SCROLLBAR_PIXEL_HEIGHT,
VERTICAL_SCROLLBAR_LEFT_BORDER, VERTICAL_SCROLLBAR_RIGHT_BORDER,
VERTICAL_SCROLLBAR_TOP_BORDER, VERTICAL_SCROLLBAR_BOTTOM_BORDER,
CHAR_TO_PIXEL_WIDTH, CHAR_TO_PIXEL_HEIGHT, PIXEL_TO_CHAR_WIDTH,
PIXEL_TO_CHAR_HEIGHT): New accessors and macros.
* frame.c (make_frame): Initialize the `can_have_scrollbars' and
`has_vertical_scrollbars' fields of the frame.
* term.c (term_init): Note that TERMCAP terminals don't support
scrollbars.
(mouse_position_hook): Document new args.
(set_vertical_scrollbar_hook, condemn_scrollbars_hook,
redeem_scrollbar_hook, judge_scrollbars_hook): New hooks.
* termhooks.h: Declare and document them.
(enum scrollbar_part): New type.
(struct input_event): Describe the new form of the scrollbar_click
event type. Change `part' from a Lisp_Object to an enum
scrollbar_part. Add a new field `scrollbar'.
* keyboard.c (kbd_buffer_get_event): Pass appropriate new
parameters to *mouse_position_hook, and make_lispy_movement.
* xfns.c (x_set_vertical_scrollbar): New function.
(x_figure_window_size): Use new macros to calculate frame size.
(Fx_create_frame): Note that X Windows frames do support scroll
bars. Default to "yes".
* xterm.c: #include <X11/cursorfont.h> and "window.h".
(x_vertical_scrollbar_cursor): New variable.
(x_term_init): Initialize it.
(last_mouse_bar, last_mouse_bar_frame, last_mouse_part,
last_mouse_scroll_range_start, last_mouse_scroll_range_end): New
variables.
(XTmouse_position): Use them to return scrollbar movement events.
Take new arguments, for that purpose.
(x_window_to_scrollbar, x_scrollbar_create,
x_scrollbar_set_handle, x_scrollbar_remove, x_scrollbar_move,
XTset_scrollbar, XTcondemn_scrollbars, XTredeem_scrollbar,
XTjudge_scrollbars, x_scrollbar_expose,
x_scrollbar_background_expose, x_scrollbar_handle_click,
x_scrollbar_handle_motion): New functions to implement scrollbars.
(x_term_init): Set the termhooks.h hooks to point to them.
(x_set_window_size): Use new macros to calculate frame size. Set
vertical_scrollbar_extra field.
(x_make_frame_visible): Use the frame accessor
FRAME_HAS_VERTICAL_SCROLLBARS to decide if we need to map the
frame's subwindows as well.
(XTread_socket): Use new size-calculation macros from xterm.h when
processing ConfigureNotify events.
(x_wm_set_size_hint): Use PIXEL_TO_CHAR_WIDTH and
PIXEL_TO_CHAR_HEIGHT macros.
* ymakefile (xdisp.o): This now depends on termhooks.h.
(xterm.o): This now depends on window.h.
| author | Jim Blandy <jimb@redhat.com> |
|---|---|
| date | Thu, 24 Dec 1992 06:17:18 +0000 |
| parents | 5677f906bf78 |
| children | 2c7997f249eb |
| rev | line source |
|---|---|
|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1 ;;; scribe.el --- scribe mode, and its idiosyncratic commands. |
|
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2 |
| 845 | 3 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
| 4 | |
|
787
3cece0106722
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
5 ;; Maintainer: FSF |
| 7 | 6 |
| 7 ;; This file might become part of GNU Emacs. | |
| 8 | |
| 9 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 10 ;; but without any warranty. No author or distributor | |
| 11 ;; accepts responsibility to anyone for the consequences of using it | |
| 12 ;; or for whether it serves any particular purpose or works at all, | |
| 13 ;; unless he says so in writing. | |
| 14 | |
| 15 ;; Everyone is granted permission to copy, modify and redistribute | |
| 16 ;; GNU Emacs, but only under the conditions described in the | |
| 17 ;; document "GNU Emacs copying permission notice". An exact copy | |
| 18 ;; of the document is supposed to have been given to you along with | |
| 19 ;; GNU Emacs so that you can know how you may redistribute it all. | |
| 20 ;; It should be in a file named COPYING. Among other things, the | |
| 21 ;; copyright notice and this notice must be preserved on all copies. | |
| 22 | |
|
787
3cece0106722
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
23 ;;; Code: |
| 7 | 24 |
| 25 (defvar scribe-mode-syntax-table nil | |
| 26 "Syntax table used while in scribe mode.") | |
| 27 | |
| 28 (defvar scribe-mode-abbrev-table nil | |
| 29 "Abbrev table used while in scribe mode.") | |
| 30 | |
| 31 (defvar scribe-fancy-paragraphs nil | |
| 32 "*Non-NIL makes Scribe mode use a different style of paragraph separation.") | |
| 33 | |
| 34 (defvar scribe-electric-quote nil | |
| 35 "*Non-NIL makes insert of double quote use `` or '' depending on context.") | |
| 36 | |
| 37 (defvar scribe-electric-parenthesis nil | |
| 38 "*Non-NIL makes parenthesis char ( (]}> ) automatically insert its close | |
| 39 if typed after an @Command form.") | |
| 40 | |
| 41 (defconst scribe-open-parentheses "[({<" | |
| 42 "Open parenthesis characters for Scribe.") | |
| 43 | |
| 44 (defconst scribe-close-parentheses "])}>" | |
| 1539 | 45 "Close parenthesis characters for Scribe. |
| 46 These should match up with `scribe-open-parenthesis'.") | |
| 7 | 47 |
| 48 (if (null scribe-mode-syntax-table) | |
| 49 (let ((st (syntax-table))) | |
| 50 (unwind-protect | |
| 51 (progn | |
| 52 (setq scribe-mode-syntax-table (copy-syntax-table | |
| 53 text-mode-syntax-table)) | |
| 54 (set-syntax-table scribe-mode-syntax-table) | |
| 55 (modify-syntax-entry ?\" " ") | |
| 56 (modify-syntax-entry ?\\ " ") | |
| 57 (modify-syntax-entry ?@ "w ") | |
| 58 (modify-syntax-entry ?< "(> ") | |
| 59 (modify-syntax-entry ?> ")< ") | |
| 60 (modify-syntax-entry ?[ "(] ") | |
| 61 (modify-syntax-entry ?] ")[ ") | |
| 62 (modify-syntax-entry ?{ "(} ") | |
| 63 (modify-syntax-entry ?} "){ ") | |
| 64 (modify-syntax-entry ?' "w ")) | |
| 65 (set-syntax-table st)))) | |
| 66 | |
| 67 (defvar scribe-mode-map nil) | |
| 68 | |
| 69 (if scribe-mode-map | |
| 70 nil | |
| 71 (setq scribe-mode-map (make-sparse-keymap)) | |
| 72 (define-key scribe-mode-map "\t" 'scribe-tab) | |
| 73 (define-key scribe-mode-map "\e\t" 'tab-to-tab-stop) | |
| 74 (define-key scribe-mode-map "\es" 'center-line) | |
| 75 (define-key scribe-mode-map "\e}" 'up-list) | |
| 76 (define-key scribe-mode-map "\eS" 'center-paragraph) | |
| 77 (define-key scribe-mode-map "\"" 'scribe-insert-quote) | |
| 78 (define-key scribe-mode-map "(" 'scribe-parenthesis) | |
| 79 (define-key scribe-mode-map "[" 'scribe-parenthesis) | |
| 80 (define-key scribe-mode-map "{" 'scribe-parenthesis) | |
| 81 (define-key scribe-mode-map "<" 'scribe-parenthesis) | |
| 82 (define-key scribe-mode-map "\^cc" 'scribe-chapter) | |
| 83 (define-key scribe-mode-map "\^cS" 'scribe-section) | |
| 84 (define-key scribe-mode-map "\^cs" 'scribe-subsection) | |
| 85 (define-key scribe-mode-map "\^ce" 'scribe-insert-environment) | |
| 86 (define-key scribe-mode-map "\^c\^e" 'scribe-bracket-region-be) | |
| 87 (define-key scribe-mode-map "\^c[" 'scribe-begin) | |
| 88 (define-key scribe-mode-map "\^c]" 'scribe-end) | |
| 89 (define-key scribe-mode-map "\^ci" 'scribe-italicize-word) | |
| 90 (define-key scribe-mode-map "\^cb" 'scribe-bold-word) | |
| 91 (define-key scribe-mode-map "\^cu" 'scribe-underline-word)) | |
| 92 | |
| 258 | 93 ;;;###autoload |
| 7 | 94 (defun scribe-mode () |
| 95 "Major mode for editing files of Scribe (a text formatter) source. | |
| 96 Scribe-mode is similar text-mode, with a few extra commands added. | |
| 97 \\{scribe-mode-map} | |
| 98 | |
| 99 Interesting variables: | |
| 100 | |
| 101 scribe-fancy-paragraphs | |
| 102 Non-nil makes Scribe mode use a different style of paragraph separation. | |
| 103 | |
| 104 scribe-electric-quote | |
| 105 Non-nil makes insert of double quote use `` or '' depending on context. | |
| 106 | |
| 107 scribe-electric-parenthesis | |
| 108 Non-nil makes an open-parenthesis char (one of `([<{') | |
| 109 automatically insert its close if typed after an @Command form." | |
| 110 (interactive) | |
| 111 (kill-all-local-variables) | |
| 112 (use-local-map scribe-mode-map) | |
| 113 (setq mode-name "Scribe") | |
| 114 (setq major-mode 'scribe-mode) | |
| 115 (define-abbrev-table 'scribe-mode-abbrev-table ()) | |
| 116 (setq local-abbrev-table scribe-mode-abbrev-table) | |
| 117 (make-local-variable 'comment-start) | |
| 118 (setq comment-start "@Comment[") | |
| 119 (make-local-variable 'comment-start-skip) | |
| 120 (setq comment-start-skip (concat "@Comment[" scribe-open-parentheses "]")) | |
| 121 (make-local-variable 'comment-column) | |
| 122 (setq comment-column 0) | |
| 123 (make-local-variable 'comment-end) | |
| 124 (setq comment-end "]") | |
| 125 (make-local-variable 'paragraph-start) | |
| 126 (setq paragraph-start (concat "\\(^[\n\f]\\)\\|\\(^@\\w+[" | |
| 127 scribe-open-parentheses | |
| 128 "].*[" | |
| 129 scribe-close-parentheses | |
| 130 "]$\\)")) | |
| 131 (make-local-variable 'paragraph-separate) | |
| 132 (setq paragraph-separate (if scribe-fancy-paragraphs | |
| 133 paragraph-start "^$")) | |
| 134 (make-local-variable 'compile-command) | |
| 135 (setq compile-command (concat "scribe " (buffer-file-name))) | |
| 136 (set-syntax-table scribe-mode-syntax-table) | |
| 137 (run-hooks 'text-mode-hook 'scribe-mode-hook)) | |
| 138 | |
| 139 (defun scribe-tab () | |
| 140 (interactive) | |
| 141 (insert "@\\")) | |
| 142 | |
| 143 ;; This algorithm could probably be improved somewhat. | |
| 144 ;; Right now, it loses seriously... | |
| 145 | |
| 146 (defun scribe () | |
| 147 "Run Scribe on the current buffer." | |
| 148 (interactive) | |
| 149 (call-interactively 'compile)) | |
| 150 | |
| 151 (defun scribe-envelop-word (string count) | |
| 1539 | 152 "Surround current word with Scribe construct @STRING[...]. |
| 153 COUNT specifies how many words to surround. A negative count means | |
| 154 to skip backward." | |
| 7 | 155 (let ((spos (point)) (epos (point)) (ccoun 0) noparens) |
| 156 (if (not (zerop count)) | |
| 157 (progn (if (= (char-syntax (preceding-char)) ?w) | |
| 158 (forward-sexp (min -1 count))) | |
| 159 (setq spos (point)) | |
| 160 (if (looking-at (concat "@\\w[" scribe-open-parentheses "]")) | |
| 161 (forward-char 2) | |
| 162 (goto-char epos) | |
| 163 (skip-chars-backward "\\W") | |
| 164 (forward-char -1)) | |
| 165 (forward-sexp (max count 1)) | |
| 166 (setq epos (point)))) | |
| 167 (goto-char spos) | |
| 168 (while (and (< ccoun (length scribe-open-parentheses)) | |
| 169 (save-excursion | |
| 170 (or (search-forward (char-to-string | |
| 171 (aref scribe-open-parentheses ccoun)) | |
| 172 epos t) | |
| 173 (search-forward (char-to-string | |
| 174 (aref scribe-close-parentheses ccoun)) | |
| 175 epos t))) | |
| 176 (setq ccoun (1+ ccoun)))) | |
| 177 (if (>= ccoun (length scribe-open-parentheses)) | |
| 178 (progn (goto-char epos) | |
| 179 (insert "@end(" string ")") | |
| 180 (goto-char spos) | |
| 181 (insert "@begin(" string ")")) | |
| 182 (goto-char epos) | |
| 183 (insert (aref scribe-close-parentheses ccoun)) | |
| 184 (goto-char spos) | |
| 185 (insert "@" string (aref scribe-open-parentheses ccoun)) | |
| 186 (goto-char epos) | |
| 187 (forward-char 3) | |
| 188 (skip-chars-forward scribe-close-parentheses)))) | |
| 189 | |
| 190 (defun scribe-underline-word (count) | |
| 191 "Underline COUNT words around point by means of Scribe constructs." | |
| 192 (interactive "p") | |
| 193 (scribe-envelop-word "u" count)) | |
| 194 | |
| 195 (defun scribe-bold-word (count) | |
| 196 "Boldface COUNT words around point by means of Scribe constructs." | |
| 197 (interactive "p") | |
| 198 (scribe-envelop-word "b" count)) | |
| 199 | |
| 200 (defun scribe-italicize-word (count) | |
| 201 "Italicize COUNT words around point by means of Scribe constructs." | |
| 202 (interactive "p") | |
| 203 (scribe-envelop-word "i" count)) | |
| 204 | |
| 205 (defun scribe-begin () | |
| 206 (interactive) | |
| 207 (insert "\n") | |
| 208 (forward-char -1) | |
| 209 (scribe-envelop-word "Begin" 0) | |
| 210 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
| 211 | |
| 212 (defun scribe-end () | |
| 213 (interactive) | |
| 214 (insert "\n") | |
| 215 (forward-char -1) | |
| 216 (scribe-envelop-word "End" 0) | |
| 217 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
| 218 | |
| 219 (defun scribe-chapter () | |
| 220 (interactive) | |
| 221 (insert "\n") | |
| 222 (forward-char -1) | |
| 223 (scribe-envelop-word "Chapter" 0) | |
| 224 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
| 225 | |
| 226 (defun scribe-section () | |
| 227 (interactive) | |
| 228 (insert "\n") | |
| 229 (forward-char -1) | |
| 230 (scribe-envelop-word "Section" 0) | |
| 231 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
| 232 | |
| 233 (defun scribe-subsection () | |
| 234 (interactive) | |
| 235 (insert "\n") | |
| 236 (forward-char -1) | |
| 237 (scribe-envelop-word "SubSection" 0) | |
| 238 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
| 239 | |
| 240 (defun scribe-bracket-region-be (env min max) | |
| 241 (interactive "sEnvironment: \nr") | |
| 242 (save-excursion | |
| 243 (goto-char max) | |
| 244 (insert "@end(" env ")\n") | |
| 245 (goto-char min) | |
| 246 (insert "@begin(" env ")\n"))) | |
| 247 | |
| 248 (defun scribe-insert-environment (env) | |
| 249 (interactive "sEnvironment: ") | |
| 250 (scribe-bracket-region-be env (point) (point)) | |
| 251 (forward-line 1) | |
| 252 (insert ?\n) | |
| 253 (forward-char -1)) | |
| 254 | |
| 255 (defun scribe-insert-quote (count) | |
| 1539 | 256 "Insert ``, '' or \" according to preceding character. |
| 257 If `scribe-electric-quote' is non-NIL, insert ``, '' or \" according | |
| 7 | 258 to preceding character. With numeric arg N, always insert N \" characters. |
| 259 Else just insert \"." | |
| 260 (interactive "P") | |
| 261 (if (or count (not scribe-electric-quote)) | |
| 262 (self-insert-command (prefix-numeric-value count)) | |
| 263 (let (lastfore lastback lastquote) | |
| 264 (insert | |
| 265 (cond | |
| 266 ((= (preceding-char) ?\\) ?\") | |
| 267 ((bobp) "``") | |
| 268 (t | |
| 269 (setq lastfore (save-excursion (and (search-backward | |
| 270 "``" (- (point) 1000) t) | |
| 271 (point))) | |
| 272 lastback (save-excursion (and (search-backward | |
| 273 "''" (- (point) 1000) t) | |
| 274 (point))) | |
| 275 lastquote (save-excursion (and (search-backward | |
| 276 "\"" (- (point) 100) t) | |
| 277 (point)))) | |
| 278 (if (not lastquote) | |
| 279 (cond ((not lastfore) "``") | |
| 280 ((not lastback) "''") | |
| 281 ((> lastfore lastback) "''") | |
| 282 (t "``")) | |
| 283 (cond ((and (not lastback) (not lastfore)) "\"") | |
| 284 ((and lastback (not lastfore) (> lastquote lastback)) "\"") | |
| 285 ((and lastback (not lastfore) (> lastback lastquote)) "``") | |
| 286 ((and lastfore (not lastback) (> lastquote lastfore)) "\"") | |
| 287 ((and lastfore (not lastback) (> lastfore lastquote)) "''") | |
| 288 ((and (> lastquote lastfore) (> lastquote lastback)) "\"") | |
| 289 ((> lastfore lastback) "''") | |
| 290 (t "``"))))))))) | |
| 291 | |
| 292 (defun scribe-parenthesis (count) | |
| 293 "If scribe-electric-parenthesis is non-NIL, insertion of an open-parenthesis | |
| 294 character inserts the following close parenthesis character if the | |
| 295 preceding text is of the form @Command." | |
| 296 (interactive "P") | |
| 297 (self-insert-command (prefix-numeric-value count)) | |
| 298 (let (at-command paren-char point-save) | |
| 299 (if (or count (not scribe-electric-parenthesis)) | |
| 300 nil | |
| 301 (save-excursion | |
| 302 (forward-char -1) | |
| 303 (setq point-save (point)) | |
| 304 (skip-chars-backward (concat "^ \n\t\f" scribe-open-parentheses)) | |
| 305 (setq at-command (and (equal (following-char) ?@) | |
| 306 (/= (point) (1- point-save))))) | |
| 307 (if (and at-command | |
| 308 (setq paren-char | |
| 309 (string-match (regexp-quote | |
| 310 (char-to-string (preceding-char))) | |
| 311 scribe-open-parentheses))) | |
| 312 (save-excursion | |
| 313 (insert (aref scribe-close-parentheses paren-char))))))) | |
|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
314 |
|
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
315 ;;; scribe.el ends here |
