]> code.delx.au - gnu-emacs-elpa/blob - packages/notes-mode/notes-aux.el
8b5e62eaf7c76285a742380ef104f8f075eac6b8
[gnu-emacs-elpa] / packages / notes-mode / notes-aux.el
1
2 ;;;
3 ;;; notes-aux.el
4 ;;; auxiliary functions for notes-mode and friends
5 ;;; $Id: notes-aux.el,v 1.10 2000/03/24 21:36:33 johnh Exp $
6 ;;;
7 ;;; Copyright (C) 1994,1995,1998 by John Heidemann
8 ;;; Comments to <johnh@isi.edu>.
9 ;;;
10 ;;; This file is under the Gnu Public License, version 2.
11 ;;;
12
13 \f
14 ;;;
15 ;;; generic-{beginning,end}-of-defun
16 ;;; I use in tex-mode and notes-mode
17 ;;;
18
19 ;;;###autoload
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)
23 )
24
25 ;;;###autoload
26 (defun generic-end-of-defun (regexp)
27 "* Go to the end of defun identified by REGEXP."
28 (let
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)
36 ))
37 )
38
39
40 ;;;###autoload
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))
49 default))
50
51 \f
52 ;;;
53 ;;; get-{beginning,end}-of-line
54 ;;; Simple functions for a simple world.
55 ;;;
56
57 ;;;###autoload
58 (defun get-beginning-of-line ()
59 "Return the boln as a position."
60 (save-excursion
61 (beginning-of-line)
62 (point)))
63
64 ;;;###autoload
65 (defun get-end-of-line ()
66 "Return the boln as a position."
67 (save-excursion
68 (end-of-line)
69 (point)))
70
71
72 ;;;###autoload
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."
76 ; (require 'calendar)
77 ; (let* ((date (if calendar-date
78 ; calendar-date
79 ; (calendar-current-date)))
80 ; (month (car date))
81 ; (day (nth 1 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)
88 (if (null time)
89 (setq time (current-time)))
90 (format-time-string notes-file-form time))
91
92 (defun notes-file-to-epoch (file)
93 "* Convert a notes FILE to an epoch time."
94 (string-match notes-file-regexp file)
95 (let
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)))))
99 (if (< y 1900)
100 (setq y (+ y 1900)))
101 (if (< y 1970)
102 (setq y (+ y 100)))
103 (encode-time 0 0 12 d m y)))
104
105 (defun notes-file-to-url (file &optional tag)
106 "* Convert a notes FILE to a URL with an optional TAG."
107 (let
108 ((epoch (notes-file-to-epoch file)))
109 (concat
110 notes-url-prefix
111 (format-time-string notes-int-form epoch)
112 "/"
113 (format-time-string notes-file-form epoch)
114 (if tag "#* " "")
115 tag)))
116
117 (provide 'notes-aux)