all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ian Zimmerman <bayard@newsguy.com>
Subject: Re: Browse skeleton positions
Date: 11 Nov 2003 09:49:20 -0800	[thread overview]
Message-ID: <87smkuiyn3.fsf@newsguy.com> (raw)
In-Reply-To: 87y8uy69ag.fsf@newsguy.com

;;; skelposn.el --- browse skeleton positions after insertion
;; Copyright (C) Ian Zimmerman, October 2003
;; Terms: GNU General Public License, Version 2

(defconst skeleton-position-mode-map
  (let ((kmap (make-sparse-keymap)))
    (suppress-keymap kmap)
    (define-key kmap "q" 'turn-off-skeleton-position-mode)
    (define-key kmap "\C-m" 'skeleton-position-exit)
    (define-key kmap "n" 'skeleton-position-next)
    (define-key kmap "p" 'skeleton-position-prev)
    (define-key kmap "a" 'skeleton-position-first)
    (define-key kmap "z" 'skeleton-position-last)
    kmap)
  "Keymap used in Skeleton Position mode.")

(defvar skeleton-position-carpal-mode-prefix [?\C-c ?+]
  "*Prefix key sequence for commands in Skeleton Position Carpal mode.")

(defconst skeleton-position-carpal-mode-map
  (let ((kmap (make-sparse-keymap)))
    (define-key kmap skeleton-position-carpal-mode-prefix skeleton-position-mode-map)
    kmap)
  "Keymap used in Skeleton Position Carpal mode.")

(defvar skeleton-position-max-list-length 50
  "*How many markers per buffer to keep in skeleton position mode.
If nil or negative, the lists of markers are allowed to grow
without limit, which can slow down Emacs dramatically.")

\f

;;;###autoload
(define-minor-mode skeleton-position-mode
  "Set or toggle the Skeleton Position minor mode.
\\<skeleton-position-mode-map>  This mode provides an interface to
browse the list of interesting position after a skeleton is inserted.

\\[skeleton-position-next] - Move to the next marker in `skeleton-position-marker-list'.
\\[skeleton-position-prev] - Move to the previous marker in `skeleton-position-marker-list'.
\\[skeleton-position-first] - Move to the first marker in `skeleton-position-marker-list'.
\\[skeleton-position-last] - Move to the last marker in `skeleton-position-marker-list'.
\\[skeleton-position-exit] - Clean up old skeleton positions and exit Skeleton Position mode."
  nil " SkelPosn" skeleton-position-mode-map)

;;;###autoload
(defun turn-on-skeleton-position-mode ()
  "Turn on the Skeleton Position minor mode."
  (interactive)
  (skeleton-position-mode 1))

(defun turn-off-skeleton-position-mode ()
  "Turn off the Skeleton Position minor mode."
  (interactive)
  (skeleton-position-mode 0))

(defvar skeleton-position-marker-list nil
  "List of markers pointing to skeleton positions in a buffer.")

(make-variable-buffer-local 'skeleton-position-marker-list)

(defvar skeleton-position-push-mark nil
  "\\<skeleton-position-mode-map>\
When set, causes \\[skeleton-position-next] and \\[skeleton-position-prev] \
in Skeleton Position mode to push a mark at point.")

(make-variable-buffer-local 'skeleton-position-push-mark)

(defvar skeleton-position-current nil
  "\\<skeleton-position-mode-map>\
The last position visited by \\[skeleton-position-next] or \\[skeleton-position-prev] \
in Skeleton Position mode, as a pointer into `skeleton-position-marker-list'.")

(make-variable-buffer-local 'skeleton-position-current)

(defun skeleton-end-hook-skelposn ()
  (setq skeleton-position-marker-list
        (append
         (nreverse
          (mapcar
           (lambda (p) (copy-marker p t))
           skeleton-positions))
         skeleton-position-marker-list))
  (let ((l (length skeleton-position-marker-list)))
    (when (and (integerp skeleton-position-max-list-length)
               (>= skeleton-position-max-list-length 0)
               (< skeleton-position-max-list-length l))
      (let* ((rest-length (- l skeleton-position-max-list-length))
             (rest
              (nthcdr
               skeleton-position-max-list-length
               skeleton-position-marker-list))
             (head (nbutlast skeleton-position-marker-list rest-length)))
        (when (and (consp skeleton-position-current)
                   (memq (car skeleton-position-current) rest))
          (setq skeleton-position-current nil))
        (mapcar (lambda (m) (set-marker m nil)) rest)
        (setq skeleton-position-marker-list head))))
  (when (and skeleton-position-marker-list
             (null skeleton-position-current))
    (setq skeleton-position-push-mark t)))  

(unless (featurep 'skelposn)
  (add-hook 'skeleton-end-hook 'skeleton-end-hook-skelposn))

(defun skeleton-position-next (&optional n)
  "Move to the next marker in `skeleton-position-marker-list'.

With an argument N, move to the Nth next marker on the list,
after `skeleton-position-current' instead.
If N is zero or negative, move to the Nth previous marker on the list.
The first call after a skeleton is inserted pushes a mark before moving."
  (interactive "p")
  (if (< n 0) (skeleton-position-prev n)
    (unless skeleton-position-current
      (setq skeleton-position-current (last skeleton-position-marker-list)))
    (while (> n 0)
      (while (and skeleton-position-current
                  (cdr skeleton-position-current)
                  (> n 0))
        (setq skeleton-position-current (cdr skeleton-position-current)
              n (1- n)))
      (when (> n 0)
        (setq n (1- n)
              skeleton-position-current skeleton-position-marker-list)))
    (when (null skeleton-position-current) (error "No more skeleton positions"))
    (when skeleton-position-push-mark
      (when (/= (point) (car skeleton-position-current)) (push-mark))
      (setq skeleton-position-push-mark nil))
    (goto-char (car skeleton-position-current))))

(defun skeleton-position-prev (&optional n)
  "Move to the previous marker in `skeleton-position-marker-list'.

With an argument N, move to the Nth previous marker on the list,
before `skeleton-position-current' instead.
If N is zero or negative, move to the Nth next marker on the list.
The first call after a skeleton is inserted pushes a mark before moving."
  (interactive "p")
  (if (< n 0) (skeleton-position-next n)
    (unless skeleton-position-current
      (setq skeleton-position-current skeleton-position-marker-list))
    (setq skeleton-position-marker-list (nreverse skeleton-position-marker-list))
    (unwind-protect
        (while (> n 0)
          (while (and skeleton-position-current
                      (cdr skeleton-position-current)
                      (> n 0))
            (setq skeleton-position-current (cdr skeleton-position-current)
                  n (1- n)))
          (when (> n 0)
            (setq n (1- n)
                  skeleton-position-current skeleton-position-marker-list)))
      (setq skeleton-position-marker-list (nreverse skeleton-position-marker-list)))
    (when (null skeleton-position-current) (error "No more skeleton positions"))
    (when skeleton-position-push-mark
      (when (/= (point) (car skeleton-position-current)) (push-mark))
      (setq skeleton-position-push-mark nil))
    (goto-char (car skeleton-position-current))))

(defun skeleton-position-first ()
  "Move to the first marker in `skeleton-position-marker-list'."
  (interactive)
  (setq skeleton-position-current skeleton-position-marker-list)
  (when (null skeleton-position-current) (error "No more skeleton positions"))
  (when skeleton-position-push-mark
    (when (/= (point) (car skeleton-position-current)) (push-mark))
    (setq skeleton-position-push-mark nil))
  (goto-char (car skeleton-position-current)))  

(defun skeleton-position-last ()
  "Move to the last marker in `skeleton-position-marker-list'."
  (interactive)
  (setq skeleton-position-current (last skeleton-position-marker-list))
  (when (null skeleton-position-current) (error "No more skeleton positions"))
  (when skeleton-position-push-mark
    (when (/= (point) (car skeleton-position-current)) (push-mark))
    (setq skeleton-position-push-mark nil))
  (goto-char (car skeleton-position-current)))  

(defun skeleton-position-cleanup ()
  (when skeleton-position-current
    (let ((rest (cdr skeleton-position-current)))
      (setcdr skeleton-position-current nil)
      (setq skeleton-position-current nil)
      (mapcar (lambda (m) (set-marker m nil)) skeleton-position-marker-list)
      (setq skeleton-position-marker-list rest))))  

(defun skeleton-position-exit ()
  "Clean up old skeleton positions and exit Skeleton Position mode."
  (interactive)
  (skeleton-position-cleanup)
  (turn-off-skeleton-position-mode))

\f

;;;###autoload
(define-minor-mode skeleton-position-carpal-mode
  "Set or toggle the Skeleton Position Carpal minor mode.
\\<skeleton-position-carpal-mode-map> This mode provides an interface to
browse the list of interesting position after a skeleton is inserted.
It is like `skeleton-position-mode', but does not rebind any normal
editing keystrokes.

\\[skeleton-position-carpal-next] - Move to the next marker in `skeleton-position-marker-list'.
\\[skeleton-position-carpal-prev] - Move to the previous marker in `skeleton-position-marker-list'.
\\[skeleton-position-carpal-first] - Move to the first marker in `skeleton-position-marker-list'.
\\[skeleton-position-carpal-last] - Move to the last marker in `skeleton-position-marker-list'.
\\[skeleton-position-carpal-exit] - Clean up old skeleton positions and exit Skeleton Position Carpal mode."
  nil " SkelCarp" skeleton-position-carpal-mode-map)

(defalias 'skeleton-position-carpal-next 'skeleton-position-next)
(defalias 'skeleton-position-carpal-prev 'skeleton-position-prev)
(defalias 'skeleton-position-carpal-first 'skeleton-position-first)
(defalias 'skeleton-position-carpal-last 'skeleton-position-last)

;;;###autoload
(defun turn-on-skeleton-position-carpal-mode ()
  "Turn on the Skeleton Position Carpal minor mode."
  (interactive)
  (skeleton-position-carpal-mode 1))

(defun turn-off-skeleton-position-carpal-mode ()
  "Turn off the Skeleton Position Carpal minor mode."
  (interactive)
  (skeleton-position-carpal-mode 0))

(defun skeleton-position-carpal-exit ()
  "Clean up old skeleton positions and exit Skeleton Position Carpal mode."
  (interactive)
  (skeleton-position-cleanup)
  (turn-off-skeleton-position-carpal-mode))

\f
;;;###autoload
(defun skeleton-position-reset ()
  "Clean up all saved skeleton positions."
  (interactive)
  (mapcar (lambda (m) (set-marker m nil)) skeleton-position-marker-list)
  (setq skeleton-position-marker-list nil)
  (setq skeleton-position-current nil))

(provide 'skelposn)

;;; skelposn.el ends here

-- 
"Rap music is our punishment for neglecting music education."
An anonymous teacher

      reply	other threads:[~2003-11-11 17:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87vfqnygi7.fsf@newsguy.com>
2003-10-17 20:42 ` Browse skeleton positions Stefan Monnier
2003-10-18 17:58   ` Ian Zimmerman
2003-10-19 23:36     ` Stefan Monnier
2003-10-30 23:57       ` Ian Zimmerman
2003-10-31 17:28         ` Stefan Monnier
2003-11-02 16:10           ` Ian Zimmerman
2003-11-11 17:49             ` Ian Zimmerman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87smkuiyn3.fsf@newsguy.com \
    --to=bayard@newsguy.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.