view shared/refInsert.el @ 0:107d592c5f4a

DICE versions, used by pers/common, recursive, I think/hope
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Mon, 08 Feb 2021 11:44:37 +0000
parents
children
line wrap: on
line source

;;; refInsert.el --- replace url with ref, resolve at end

(provide 'refInsert)
;;; Code:

(defun reference ()  
  "Insert a reference"
  (interactive)
  (let ((current-point (point))
	(beginning (search-backward "
" (point-min) t)))
    (save-excursion 
      (if (not (equal beginning nil))
	  (goto-char beginning))
      (let ((url-point (search-forward-regexp "[a-zA-Z]+:[^ 
]+" (+ current-point 1) t))
	    (ref "http://www.w3.org/DOM"))
	(if (not (equal url-point nil))
	    (progn 
	      (setq ref (buffer-substring (match-beginning 0) (match-end 0)))
	      (replace-match "")
	      (setq current-point (point))))
	
	(setq ref (read-string "Reference? " ref))
	(setq nbReferences 
	      (string-to-number (read-string "Reference number? "
					     (number-to-string (+ nbReferences 1)))))
	(let ((search-p (search-forward-regexp "^-- 
" (point-max) t)))
	  (if (equal search-p nil) 
	      (end-of-buffer)
	    (progn (goto-char search-p) (previous-line 1)))
	  (insert (concat "[" (number-to-string nbReferences) "] "
			  ref))
	  (newline))))
    (goto-char current-point)
    (insert (concat "[" (number-to-string nbReferences) "]"))
    ))

(setq nbReferences 0)

(add-hook 'mail-setup-hook (lambda () (setq nbReferences 0)))
(add-hook 'gnus-message-setup-hook (lambda () (setq nbReferences 0)))

;;; %F ends here