4 ;;; auxiliary functions for notes-mode and friends
5 ;;; $Id: notes-aux.el,v 1.10 2000/03/24 21:36:33 johnh Exp $
7 ;;; Copyright (C) 1994,1995,1998 by John Heidemann
8 ;;; Comments to <johnh@isi.edu>.
10 ;;; This file is under the Gnu Public License, version 2.
15 ;;; generic-{beginning,end}-of-defun
16 ;;; I use in tex-mode and notes-mode
20 (defun generic-beginning-of-defun (regexp)
21 "* Go to the beginning of defun identified by REGEXP."
22 (re-search-backward regexp 0 'to-limit)
26 (defun generic-end-of-defun (regexp)
27 "* Go to the end of defun identified by REGEXP."
29 ((restore-point (point)))
30 (if (looking-at regexp)
31 (goto-char (match-end 0)))
32 ;; find next section and leave cursor at section beginning
33 (if (re-search-forward regexp (point-max) 'to-limit)
34 (re-search-backward regexp 0 t)
35 ;(goto-char restore-point)
41 (defun match-substring (string count &optional default empty-default)
42 "Given STRING, return the COUNT-th element from the last match.
43 Returns DEFAULT if there is no such match,
44 or if the match is empty and EMPTY-DEFAULT is non-nil."
45 (if (and (match-beginning count)
46 (or (not empty-default)
47 (> (match-end count) (match-beginning count))))
48 (substring string (match-beginning count) (match-end count))
53 ;;; get-{beginning,end}-of-line
54 ;;; Simple functions for a simple world.
58 (defun get-beginning-of-line ()
59 "Return the boln as a position."
65 (defun get-end-of-line ()
66 "Return the boln as a position."
73 ;(defun notes-format-date (&optional calendar-date)
74 ; "Format the calendar-date-style DATE up to be a notes-format date.
75 ;If no DATE is specified, use today's date."
77 ; (let* ((date (if calendar-date
79 ; (calendar-current-date)))
82 ; (year (nth 2 date)))
83 ; (format "%02d%02d%02d" (- year 1900) month day)))
84 (defun notes-format-date (&optional time)
85 "Format the TIME up to be a notes-format date.
86 If no TIME is specified, use today's date."
87 (require 'notes-variables)
89 (setq time (current-time)))
90 (format-time-string notes-file-form time))
92 (defun notes-file-to-epoch (file)
93 "* Convert a notes FILE to an epoch time."
94 (string-match notes-file-regexp file)
96 ((y (string-to-int (substring file (match-beginning 1) (match-end 1))))
97 (m (string-to-int (substring file (match-beginning 2) (match-end 2))))
98 (d (string-to-int (substring file (match-beginning 3) (match-end 3)))))
103 (encode-time 0 0 12 d m y)))
105 (defun notes-file-to-url (file &optional tag)
106 "* Convert a notes FILE to a URL with an optional TAG."
108 ((epoch (notes-file-to-epoch file)))
111 (format-time-string notes-int-form epoch)
113 (format-time-string notes-file-form epoch)