| [6] | 1 | ;;; -*- Package: hemlock; Log: hemlock.log -*-
|
|---|
| 2 | ;;;
|
|---|
| 3 | ;;; **********************************************************************
|
|---|
| 4 | ;;; This code was written as part of the CMU Common Lisp project at
|
|---|
| 5 | ;;; Carnegie Mellon University, and has been placed in the public domain.
|
|---|
| 6 | ;;;
|
|---|
| 7 | #+CMU (ext:file-comment
|
|---|
| 8 | "$Header$")
|
|---|
| 9 | ;;;
|
|---|
| 10 | ;;; **********************************************************************
|
|---|
| 11 | ;;;
|
|---|
| 12 | ;;; This is an italicized comment.
|
|---|
| 13 |
|
|---|
| 14 | (in-package :hemlock)
|
|---|
| 15 |
|
|---|
| 16 | (defun delete-line-italic-marks (line)
|
|---|
| 17 | (dolist (m (hi::line-marks line))
|
|---|
| 18 | (when (and (hi::fast-font-mark-p m)
|
|---|
| 19 | (eql (hi::font-mark-font m) 1))
|
|---|
| 20 | (delete-font-mark m))))
|
|---|
| 21 |
|
|---|
| 22 | (defun set-comment-font (region font)
|
|---|
| 23 | (do ((line (mark-line (region-start region))
|
|---|
| 24 | (line-next line))
|
|---|
| 25 | (end (line-next (mark-line (region-end region)))))
|
|---|
| 26 | ((eq line end))
|
|---|
| 27 | (delete-line-italic-marks line)
|
|---|
| 28 | (let ((pos (position #\; (the simple-string (line-string line)))))
|
|---|
| 29 | (when pos
|
|---|
| 30 | (font-mark line pos font :left-inserting)))))
|
|---|
| 31 |
|
|---|
| 32 | (defun delete-italic-marks-region (region)
|
|---|
| 33 | (do ((line (mark-line (region-start region))
|
|---|
| 34 | (line-next line))
|
|---|
| 35 | (end (line-next (mark-line (region-end region)))))
|
|---|
| 36 | ((eq line end))
|
|---|
| 37 | (delete-line-italic-marks line)))
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | (defmode "Italic"
|
|---|
| 41 | :setup-function
|
|---|
| 42 | #'(lambda (buffer) (set-comment-font (buffer-region buffer) 1))
|
|---|
| 43 | :cleanup-function
|
|---|
| 44 | #'(lambda (buffer) (delete-italic-marks-region (buffer-region buffer))))
|
|---|
| 45 |
|
|---|
| 46 | (define-file-option "Italicize Comments" (buffer value)
|
|---|
| 47 | (declare (ignore value))
|
|---|
| 48 | (setf (buffer-minor-mode buffer "Italic") t))
|
|---|
| 49 |
|
|---|
| 50 | (defcommand "Italic Comment Mode" (p)
|
|---|
| 51 | "Toggle \"Italic\" mode in the current buffer. When in \"Italic\" mode,
|
|---|
| 52 | semicolon comments are displayed in an italic font."
|
|---|
| 53 | "Toggle \"Italic\" mode in the current buffer."
|
|---|
| 54 | (declare (ignore p))
|
|---|
| 55 | (setf (buffer-minor-mode (current-buffer) "Italic")
|
|---|
| 56 | (not (buffer-minor-mode (current-buffer) "Italic"))))
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | (defcommand "Start Italic Comment" (p)
|
|---|
| 60 | "Italicize the text in this comment."
|
|---|
| 61 | "Italicize the text in this comment."
|
|---|
| 62 | (declare (ignore p))
|
|---|
| 63 | (let* ((point (current-point))
|
|---|
| 64 | (pos (mark-charpos point))
|
|---|
| 65 | (line (mark-line point)))
|
|---|
| 66 | (delete-line-italic-marks line)
|
|---|
| 67 | (insert-character point #\;)
|
|---|
| 68 | (font-mark
|
|---|
| 69 | line
|
|---|
| 70 | (or (position #\; (the simple-string (line-string line))) pos)
|
|---|
| 71 | 1
|
|---|
| 72 | :left-inserting)))
|
|---|
| 73 |
|
|---|
| 74 | (bind-key "Start Italic Comment" #k";" :mode "Italic")
|
|---|