tdiary-contrib 5.4.0 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,29 +1,30 @@
1
- ;;; tdiary-mode.el -- Major mode for tDiary editing -*- coding: utf-8 -*-
2
-
1
+ ;;; tdiary-mode.el --- Major mode for tDiary editing -*- lexical-binding: t; -*-
2
+ ;;
3
3
  ;; Copyright (C) 2002 Junichiro Kita
4
-
4
+ ;; 2019-2026 Youhei SASAKI
5
5
  ;; Author: Junichiro Kita <kita@kitaj.no-ip.com>
6
-
7
- ;; $Id: tdiary-mode.el,v 1.4 2005/08/19 08:36:43 tadatadashi Exp $
6
+ ;; Youhei SASAKI <uwabami@gfd-dennou.org>
7
+ ;; Version: 0.0.3
8
+ ;; Keywords: comm
9
+ ;; License: GPL-2.0+
10
+ ;; Homepage: https://github.com/tdiary-contrib/util/tdiary-mode
8
11
  ;;
9
12
  ;; This program is free software; you can redistribute it and/or
10
13
  ;; modify it under the terms of the GNU General Public License as
11
14
  ;; published by the Free Software Foundation; either version 2, or (at
12
15
  ;; your option) any later version.
13
-
16
+ ;;
14
17
  ;; This program is distributed in the hope that it will be useful, but
15
18
  ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16
- ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
+ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
20
  ;; General Public License for more details.
18
-
21
+ ;;
19
22
  ;; You should have received a copy of the GNU General Public License
20
23
  ;; along with this program; see the file COPYING. If not, write to the
21
24
  ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22
25
  ;; Boston, MA 02111-1307, USA.
23
-
26
+ ;;
24
27
  ;;; Commentary:
25
-
26
- ;; usage:
27
28
  ;;
28
29
  ;; Put the following in your .emacs file:
29
30
  ;;
@@ -31,72 +32,153 @@
31
32
  ;; ("my 2nd diary" "http://example.com/tdiary2/")))
32
33
  ;; (setq tdiary-text-directory (expand-file-name "~/path-to-saved-diary"))
33
34
  ;; (setq tdiary-browser-function 'browse-url)
34
- ;; (autoload 'tdiary-mode "tdiary-mode" nil t)
35
- ;; (autoload 'tdiary-new "tdiary-mode" nil t)
36
- ;; (autoload 'tdiary-new-diary "tdiary-mode" nil t)
37
- ;; (autoload 'tdiary-replace "tdiary-mode" nil t)
38
35
  ;; (add-to-list 'auto-mode-alist
39
- ;; '("\\.td$" . tdiary-mode))
36
+ ;; '("\\.td$" . tdiary-mode))
40
37
  ;;
41
38
  ;; You can use your own plugin completion, keybindings:
42
39
  ;;
43
40
  ;; (setq tdiary-plugin-definition
44
- ;; '(
45
- ;; ("STRONG" ("<%=STRONG %Q|" (p "str: ") "| %>"))
46
- ;; ("PRE" ("<%=PRE %Q|" (p "str: ") "| %>"))
47
- ;; ("CITE" ("<%=CITE %Q|" (p "str: ") "| %>"))
48
- ;; ))
41
+ ;; '(
42
+ ;; ("STRONG" ("<%=STRONG %Q|" (p "str: ") "| %>"))
43
+ ;; ("PRE" ("<%=PRE %Q|" (p "str: ") "| %>"))
44
+ ;; ("CITE" ("<%=CITE %Q|" (p "str: ") "| %>"))
45
+ ;; ))
49
46
  ;;
50
47
  ;; (add-hook 'tdiary-mode-hook
51
- ;; '(lambda ()
52
- ;; (local-set-key "\C-i" 'tdiary-complete-plugin)))
48
+ ;; '(lambda ()
49
+ ;; (local-set-key "\C-i" 'tdiary-complete-plugin)))
53
50
  ;;
54
51
  ;; If you want to save username and password cache to file:
55
52
  ;;
56
53
  ;; (setq tdiary-passwd-file (expand-file-name "~/.tdiary-pass"))
57
54
  ;;
58
- ;; then, M-x tdiary-passwd-cache-save. !!DANGEROUS!!
55
+ ;; then, M-x tdiary-passwd-cache-save. !!DANGEROUS!!
59
56
  ;;
60
- ;; see http://kitaj.no-ip.com/rw-cgi.rb?cmd=view;name=tdiary-mode
61
- ;;
62
-
63
57
  ;; ToDo:
64
- ;; - find plugin definition automatically(needs modification for plugin)
65
- ;; - bug fix
58
+ ;; - find plugin definition automatically: needs modification for plugin
59
+ ;; - Handling authinfo by `auth-source'
60
+ ;; - create test
66
61
  ;;
67
-
68
- ;;; Variable:
69
-
70
- (require 'http)
71
- (require 'poe)
62
+ ;;; Code:
63
+ (require 'network-stream)
72
64
  (require 'tempo)
73
65
 
74
- (defvar tdiary-diary-list nil
66
+ ;; ---------------------------------------------------------------------------
67
+ (defgroup tdiary nil
68
+ "Major mode for editing tDiary."
69
+ :prefix "tdiary-"
70
+ :group 'comm)
71
+
72
+ (defcustom tdiary-diary-list nil
75
73
  "List of diary list.
76
- Each element looks like (NAME URL) or (NAME URL INDEX-RB UPDATE-RB).")
74
+ Each element looks like (NAME URL) or (NAME URL INDEX-RB UPDATE-RB)."
75
+ :type '(repeat sexp)
76
+ :group 'tdiary)
77
+
78
+ (defcustom tdiary-index-rb nil
79
+ "Name of the 'index.rb'."
80
+ :type '(choice (const :tag "Default" nil) string)
81
+ :group 'tdiary)
82
+
83
+ (defcustom tdiary-update-rb "update.rb"
84
+ "Name of the 'update.rb'."
85
+ :type 'string
86
+ :group 'tdiary)
87
+
88
+ (defcustom tdiary-coding-system 'utf-8-dos
89
+ "Coding system for tDiary."
90
+ :type 'coding-system
91
+ :group 'tdiary)
92
+
93
+ (defcustom tdiary-style-mode 'html-mode
94
+ "Major mode to be used for tDiary editing."
95
+ :type 'function
96
+ :group 'tdiary)
97
+
98
+ (defcustom tdiary-plugin-initial-definition
99
+ '(("my" ("<%=my %Q|" (p "a: ") "|, %Q|" (p "str: ") "| %>"))
100
+ ("fn" ("<%=fn %Q|" (p "footnote: ") "| %>")))
101
+ "Initial definition for tDiary tempo."
102
+ :type '(repeat sexp)
103
+ :group 'tdiary)
104
+
105
+ (defcustom tdiary-passwd-file nil
106
+ "File path to save password cache."
107
+ :type '(choice (const :tag "None" nil) file)
108
+ :group 'tdiary)
109
+
110
+ (defcustom tdiary-passwd-file-mode 384 ;; == 0600
111
+ "File mode for `tdiary-passwd-file'."
112
+ :type 'integer
113
+ :group 'tdiary)
114
+
115
+ (defcustom tdiary-text-directory-mode 448 ;; == 0700
116
+ "Directory mode for `tdiary-text-directory'."
117
+ :type 'integer
118
+ :group 'tdiary)
119
+
120
+ (defcustom tdiary-csrf-key nil
121
+ "CSRF protection key. check your tdiary.conf"
122
+ :type 'string
123
+ :group 'tdiary)
124
+
125
+ (defcustom tdiary-hour-offset 0
126
+ "Offset to `current-time'.
127
+ `tdiary-today' returns (current-time + tdiary-hour-offset)."
128
+ :type 'integer
129
+ :group 'tdiary)
130
+
131
+ (defcustom tdiary-text-suffix ".td"
132
+ "Suffix for saved text files."
133
+ :type 'string
134
+ :group 'tdiary)
135
+
136
+ (defcustom tdiary-text-directory "~/.tdiary-backup/"
137
+ "Directory where diary is stored locally."
138
+ :type 'directory
139
+ :group 'tdiary)
140
+
141
+ (defcustom tdiary-text-save-p nil
142
+ "Flag for saving text.
143
+ If non-nil, tdiary buffer is associated to a real file."
144
+ :type 'boolean
145
+ :group 'tdiary)
77
146
 
147
+ (defcustom tdiary-browser-function nil
148
+ "Function to call browser.
149
+ If non-nil, `tdiary-update' calls this function."
150
+ :type '(choice (const :tag "None" nil) function)
151
+ :group 'tdiary)
152
+
153
+ (defcustom tdiary-init-file "~/.tdiary"
154
+ "Init file for tDiary-mode."
155
+ :type 'file
156
+ :group 'tdiary)
157
+
158
+ (defcustom tdiary-http-proxy-server nil
159
+ "Proxy server for HTTP."
160
+ :type '(choice (const :tag "None" nil) string)
161
+ :group 'tdiary)
162
+
163
+ (defcustom tdiary-http-proxy-port nil
164
+ "Proxy port for HTTP."
165
+ :type '(choice (const :tag "None" nil) integer)
166
+ :group 'tdiary)
167
+
168
+ (defcustom tdiary-http-timeout 10
169
+ "Timeout for HTTP in seconds."
170
+ :type 'integer
171
+ :group 'tdiary)
172
+
173
+ ;; ---------------------------------------------------------------------------
78
174
  (defvar tdiary-diary-name nil
79
175
  "Identifier for diary to be updated.")
80
176
 
81
177
  (defvar tdiary-diary-url nil
82
- "tDiary-mode updates this URL. URL should end with '/'.")
83
-
84
- (defvar tdiary-index-rb nil
85
- "Name of the 'index.rb'.")
86
-
87
- (defvar tdiary-update-rb "update.rb"
88
- "Name of the 'update.rb'.")
89
-
90
- (defvar tdiary-csrf-key nil
91
- "CSRF protection key.")
92
-
93
- (defvar tdiary-coding-system 'utf-8-dos)
178
+ "The tDiary-mode updates this URL. URL should end with '/'.")
94
179
 
95
180
  (defvar tdiary-title nil
96
- "Title of diary")
97
-
98
- (defvar tdiary-style-mode 'html-mode
99
- "Major mode to be used for tDiary editing.")
181
+ "Title of diary.")
100
182
 
101
183
  (defvar tdiary-date nil
102
184
  "Date to be updated.")
@@ -108,19 +190,11 @@ Each element looks like (NAME URL) or (NAME URL INDEX-RB UPDATE-RB).")
108
190
  It is used in `tdiary-complete-plugin'.")
109
191
 
110
192
  (defvar tdiary-tempo-tags nil
111
- "Tempo tags for tDiary mode")
193
+ "Tempo tags for tDiary mode.")
112
194
 
113
195
  (defvar tdiary-completion-finder "\\(\\(<\\|&\\|<%=\\).*\\)\\="
114
196
  "Regexp used to find tags to complete.")
115
197
 
116
- (defvar tdiary-plugin-initial-definition
117
- '(
118
- ("my" ("<%=my %Q|" (p "a: ") "|, %Q|" (p "str: ") "| %>"))
119
- ("fn" ("<%=fn %Q|" (p "footnote: ") "| %>"))
120
- )
121
- "Initial definition for tDiary tempo."
122
- )
123
-
124
198
  (defvar tdiary-edit-mode-list '(("append") ("replace")))
125
199
 
126
200
  (defvar tdiary-plugin-definition nil
@@ -132,90 +206,193 @@ template. See tempo.info for details.")
132
206
  (defvar tdiary-complete-plugin-history nil
133
207
  "Minibuffer history list for `tdiary-complete-plugin'.")
134
208
 
135
- (defvar tdiary-passwd-file nil)
136
- (defvar tdiary-passwd-file-mode 384) ;; == 0600
137
- (defvar tdiary-text-directory-mode 448) ;; == 0700
138
-
139
209
  (defvar tdiary-passwd-cache nil
140
210
  "Cache for username and password.")
141
211
 
142
- (defvar tdiary-hour-offset 0
143
- "Offset to current-time.
144
- `tdiary-today' returns (current-time + tdiary-hour-offset).")
145
-
146
- (defvar tdiary-text-suffix ".td")
147
-
148
- (defvar tdiary-text-directory nil
149
- "Directory where diary is stored.")
150
-
151
- (defvar tdiary-text-save-p nil
152
- "Flag for saving text.
153
- If non-nil, tdiary buffer is associated to a real file,
154
- named `tdiary-date' + `tdiary-text-suffix'.")
155
-
156
- (defvar tdiary-browser-function nil
157
- "Function to call browser.
158
- If non-nil, `tdiary-update' calls this function. The function
159
- is expected to accept only one argument(URL).")
160
-
161
212
  (defvar tdiary-mode-hook nil
162
213
  "Hook run when entering tDiary mode.")
163
214
 
164
- (defvar tdiary-init-file "~/.tdiary"
165
- "Init file for tDiary-mode.")
166
-
167
215
  ;(defvar tdiary-plugin-dir nil
168
216
  ; "Path to plugins. It must be a mounted file system.")
169
217
  ;(defvar tdiary-plugin-definition-regexp "^[ \t]*def[ \t]+\\(.+?\\)[ \t]*\\(?:$\\|;\\|([ \t]*\\(.*?\\)[ \t]*)\\)")
170
218
 
219
+ (defvar tdiary--request-url 'unbound
220
+ "Internal variable to pass URL request to tdiary-mode-setup.")
221
+
222
+ ;; ---------------------------------------------------------------------------
223
+
224
+ (defmacro tdiary-as-binary-process (&rest body)
225
+ "Execute `BODY' as binary. This macro is imported from apel."
226
+ `(let (selective-display
227
+ (coding-system-for-read 'binary)
228
+ (coding-system-for-write 'binary))
229
+ ,@body))
230
+
231
+ ;; derived from url.el
232
+ (defconst tdiary-url-unreserved-chars
233
+ '(
234
+ ?a ?b ?c ?d ?e ?f ?g ?h ?i ?j ?k ?l ?m ?n ?o ?p ?q ?r ?s ?t ?u ?v ?w ?x ?y ?z
235
+ ?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K ?L ?M ?N ?O ?P ?Q ?R ?S ?T ?U ?V ?W ?X ?Y ?Z
236
+ ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9
237
+ ?$ ?- ?_ ?. ?! ?~ ?* ?' ?\( ?\) ?,)
238
+ "A list of characters that are _NOT_ reserve in the URL spec.
239
+ This is taken from draft-fielding-url-syntax-02.txt - check your local
240
+ internet drafts directory for a copy.")
241
+
242
+ ;; derived from url.el
243
+ (defun tdiary-url-hexify-string (str coding)
244
+ "Escape characters in a string.
245
+ At first, encode STR using CODING, then url-hexify."
246
+ (mapconcat
247
+ (function
248
+ (lambda (char)
249
+ (if (not (memq char tdiary-url-unreserved-chars))
250
+ (if (< char 16)
251
+ (upcase (format "%%0%x" char))
252
+ (upcase (format "%%%x" char)))
253
+ (char-to-string char))))
254
+ (encode-coding-string str coding) ""))
255
+
256
+ (defun tdiary-http-fetch (url method &optional user pass data)
257
+ "Fetch via HTTP.
258
+
259
+ URL is a url to be POSTed.
260
+ METHOD is 'get or 'post.
261
+ USER and PASS must be a valid username and password, if required.
262
+ DATA is an alist, each element is in the form of (FIELD . DATA).
263
+
264
+ If no error, return a buffer which contains output from the web server.
265
+ If error, return a cons cell (ERRCODE . DESCRIPTION)."
266
+ (let (connection ssl server port path buf str len)
267
+ (string-match "^http\\(s\\)?://\\([^/:]+\\)\\(:\\([0-9]+\\)\\)?\\(/.*$\\)" url)
268
+ (setq ssl (match-string 1 url)
269
+ server (match-string 2 url)
270
+ port (string-to-number (or (match-string 4 url) (if ssl "443" "80")))
271
+ path (if tdiary-http-proxy-server url (match-string 5 url)))
272
+ (setq str (mapconcat
273
+ #'(lambda (x)
274
+ (concat (car x) "=" (cdr x)))
275
+ data "&"))
276
+ (setq len (length str))
277
+ (save-excursion
278
+ (setq buf (get-buffer-create (concat "*result from " server "*")))
279
+ (set-buffer buf)
280
+ (erase-buffer)
281
+ (setq connection
282
+ (tdiary-as-binary-process
283
+ (if ssl
284
+ (open-network-stream (concat "*request to " server "*")
285
+ buf
286
+ (or tdiary-http-proxy-server server)
287
+ (or tdiary-http-proxy-port port)
288
+ :type 'tls)
289
+ (open-network-stream (concat "*request to " server "*")
290
+ buf
291
+ (or tdiary-http-proxy-server server)
292
+ (or tdiary-http-proxy-port port)))))
293
+ (process-send-string
294
+ connection
295
+ (concat (if (eq method 'post)
296
+ (concat "POST " path)
297
+ (concat "GET " path (if (> len 0)
298
+ (concat "?" str))))
299
+ " HTTP/1.0\r\n"
300
+ (concat "Host: " server "\r\n")
301
+ "Connection: close\r\n"
302
+ "Referer: " url "\r\n"
303
+ "Content-type: application/x-www-form-urlencoded\r\n"
304
+ (if (and user pass)
305
+ (concat "Authorization: Basic "
306
+ (base64-encode-string
307
+ (concat user ":" pass))
308
+ "\r\n"))
309
+ (if (eq method 'post)
310
+ (concat "Content-length: " (int-to-string len) "\r\n"
311
+ "\r\n"
312
+ str))
313
+ "\r\n"))
314
+ (goto-char (point-min))
315
+ (while (not (search-forward "</body>" nil t))
316
+ (unless (accept-process-output connection tdiary-http-timeout)
317
+ (error "HTTP fetch: Connection timeout!"))
318
+ (goto-char (point-min)))
319
+ (goto-char (point-min))
320
+ (save-excursion
321
+ (if (re-search-forward "HTTP/1.[01] \\([0-9][0-9][0-9]\\) \\(.*\\)" nil t)
322
+ (let ((code (match-string 1))
323
+ (desc (match-string 2)))
324
+ (cond ((equal code "200")
325
+ buf)
326
+ (t
327
+ (cons code desc)))))))))
328
+
329
+ (defun tdiary-remassoc (key alist)
330
+ "Delete by side effect any elements of ALIST whose car is `equal' to KEY.
331
+ The modified ALIST is returned. If the first member of ALIST has a car
332
+ that is `equal' to KEY, there is no way to remove it by side effect;
333
+ therefore, write `(setq foo (remassoc key foo))' to be sure of changing
334
+ the value of `foo'. This function imported from apel."
335
+ (while (and (consp alist)
336
+ (or (not (consp (car alist)))
337
+ (equal (car (car alist)) key)))
338
+ (setq alist (cdr alist)))
339
+ (if (consp alist)
340
+ (let ((prev alist)
341
+ (tail (cdr alist)))
342
+ (while (consp tail)
343
+ (if (and (consp (car alist))
344
+ (equal (car (car tail)) key))
345
+ ;; `(setcdr CELL NEWCDR)' returns NEWCDR.
346
+ (setq tail (setcdr prev (cdr tail)))
347
+ (setq prev (cdr prev)
348
+ tail (cdr tail))))))
349
+ alist)
171
350
 
172
- ;;; Code:
173
351
  (defun tdiary-tempo-add-tag (def)
174
352
  (let* ((plugin (car def))
175
- (element (cadr def))
176
- (name (concat "tdiary-" plugin))
177
- (completer (concat "<%=" plugin))
178
- (doc (concat "Insert `" plugin "'"))
179
- (command (tempo-define-template name element completer doc
180
- 'tdiary-tempo-tags)))
353
+ (element (cadr def))
354
+ (name (concat "tdiary-" plugin))
355
+ (completer (concat "<%=" plugin))
356
+ (doc (concat "Insert `" plugin "'"))
357
+ (command (tempo-define-template name element completer doc
358
+ 'tdiary-tempo-tags)))
181
359
  (add-to-list 'tdiary-plugin-list (list plugin command))))
182
360
 
183
361
  (defun tdiary-tempo-define (l)
184
362
  (mapcar 'tdiary-tempo-add-tag l))
185
363
 
186
-
187
364
  ;(defun tdiary-parse-plugin-args (args)
188
365
  ; (if (null args)
189
366
  ; nil
190
367
  ; (mapcar '(lambda (x)
191
- ; (let ((l (split-string x "[ \t]*=[ \t]*")))
192
- ; (if (eq (length l) 1)
193
- ; (car l)
194
- ; l)))
195
- ; (split-string args "[ \t]*,[ \t]*"))))
368
+ ; (let ((l (split-string x "[ \t]*=[ \t]*")))
369
+ ; (if (eq (length l) 1)
370
+ ; (car l)
371
+ ; l)))
372
+ ; (split-string args "[ \t]*,[ \t]*"))))
196
373
 
197
374
  ;(defun tdiary-update-plugin-definition ()
198
375
  ; (interactive)
199
376
  ; (let ((files (directory-files tdiary-plugin-dir t ".*\\.rb$" nil t))
200
- ; (buf (generate-new-buffer "*update plugin*")))
377
+ ; (buf (generate-new-buffer "*update plugin*")))
201
378
  ; (save-excursion
202
379
  ; (save-window-excursion
203
- ; (switch-to-buffer buf)
204
- ; (mapc 'insert-file-contents files)
205
- ; (setq tdiary-plugin-definition nil)
206
- ; (while (re-search-forward tdiary-plugin-definition-regexp nil t)
207
- ; (add-to-list 'tdiary-plugin-definition
208
- ; (list (match-string 1)
209
- ; (tdiary-parse-plugin-args (match-string 2)))))
210
- ; (kill-buffer buf)))))
380
+ ; (switch-to-buffer buf)
381
+ ; (mapc 'insert-file-contents files)
382
+ ; (setq tdiary-plugin-definition nil)
383
+ ; (while (re-search-forward tdiary-plugin-definition-regexp nil t)
384
+ ; (add-to-list 'tdiary-plugin-definition
385
+ ; (list (match-string 1)
386
+ ; (tdiary-parse-plugin-args (match-string 2)))))
387
+ ; (kill-buffer buf)))))
211
388
 
212
389
  (defun tdiary-do-complete-plugin (&optional name)
213
390
  "Complete function for plugin."
214
391
  (let (command)
215
392
  (when (null name)
216
- (setq name
217
- (completing-read "plugin: " tdiary-plugin-list nil nil nil
218
- 'tdiary-complete-plugin-history)))
393
+ (setq name
394
+ (completing-read "plugin: " tdiary-plugin-list nil nil nil
395
+ 'tdiary-complete-plugin-history)))
219
396
  (setq command (cadr (assoc name tdiary-plugin-list)))
220
397
  (when command
221
398
  (funcall command))))
@@ -226,57 +403,57 @@ is expected to accept only one argument(URL).")
226
403
  If there are no completable text, call `tdiary-do-complete-plugin'."
227
404
  (interactive "*")
228
405
  (let* ((collection (tempo-build-collection))
229
- (match-info (tempo-find-match-string tempo-match-finder))
230
- (match-string (car match-info))
231
- (match-start (cdr match-info))
232
- (exact (assoc match-string collection))
233
- (compl (or (car exact)
234
- (and match-info (try-completion match-string collection)))))
406
+ (match-info (tempo-find-match-string tempo-match-finder))
407
+ (match-string (car match-info))
408
+ (match-start (cdr match-info))
409
+ (exact (assoc match-string collection))
410
+ (compl (or (car exact)
411
+ (and match-info (try-completion match-string collection)))))
235
412
  (if compl (delete-region match-start (point)))
236
413
  (cond ((or (null match-info)
237
- (null compl))
238
- (tdiary-do-complete-plugin))
239
- ((eq compl t) (tempo-insert-template
240
- (cdr (assoc match-string
241
- collection))
242
- nil))
243
- (t (if (setq exact (assoc compl collection))
244
- (tempo-insert-template (cdr exact) nil)
245
- (insert compl)
246
- (or silent (ding))
247
- (if tempo-show-completion-buffer
248
- (tempo-display-completions match-string
249
- collection)))))))
414
+ (null compl))
415
+ (tdiary-do-complete-plugin))
416
+ ((eq compl t) (tempo-insert-template
417
+ (cdr (assoc match-string
418
+ collection))
419
+ nil))
420
+ (t (if (setq exact (assoc compl collection))
421
+ (tempo-insert-template (cdr exact) nil)
422
+ (insert compl)
423
+ (or silent (ding))
424
+ (if tempo-show-completion-buffer
425
+ (tempo-display-completions match-string
426
+ collection)))))))
250
427
 
251
428
  (defun tdiary-today ()
252
429
  (let* ((offset-second (* tdiary-hour-offset 60 60))
253
- (now (current-time))
254
- (high (nth 0 now))
255
- (low (+ (nth 1 now) offset-second))
256
- (micro (nth 2 now)))
430
+ (now (current-time))
431
+ (high (nth 0 now))
432
+ (low (+ (nth 1 now) offset-second))
433
+ (micro (nth 2 now)))
257
434
  (setq high (+ high (/ low 65536))
258
- low (% low 65536))
435
+ low (% low 65536))
259
436
  (when (< low 0)
260
437
  (setq high (1- high)
261
- low (+ low 65536)))
438
+ low (+ low 65536)))
262
439
  (list high low micro)))
263
440
 
264
441
  (defun tdiary-read-username (url name)
265
442
  (let ((username (tdiary-passwd-cache-read-username url)))
266
443
  (or username
267
- (read-string (concat "User Name for '" name "': ")))))
444
+ (read-string (concat "User Name for '" name "': ")))))
268
445
 
269
446
  (defun tdiary-read-password (url name)
270
447
  (let ((password (tdiary-passwd-cache-read-password url)))
271
448
  (or password
272
- (read-passwd (concat "Password for '" name "': ")))))
449
+ (read-passwd (concat "Password for '" name "': ")))))
273
450
 
274
451
  (defun tdiary-read-date (date)
275
452
  (while (not (string-match
276
- "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"
277
- (setq date (read-string "Date: "
278
- (or date
279
- (format-time-string "%Y%m%d" (tdiary-today)))))))
453
+ "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"
454
+ (setq date (read-string "Date: "
455
+ (or date
456
+ (format-time-string "%Y%m%d" (tdiary-today)))))))
280
457
  nil)
281
458
  date)
282
459
 
@@ -286,54 +463,57 @@ If there are no completable text, call `tdiary-do-complete-plugin'."
286
463
  (defun tdiary-read-mode (mode)
287
464
  (let ((default (caar tdiary-edit-mode-list)))
288
465
  (completing-read "Editing mode: " tdiary-edit-mode-list
289
- nil t (or mode default) nil default)))
466
+ nil t (or mode default) nil default)))
290
467
 
291
468
  (defun tdiary-passwd-file-load ()
292
469
  "Load password alist."
293
- (save-excursion
294
- (let ((buf (get-buffer-create "*tdiary-passwd-cache*")))
295
- (when (and tdiary-passwd-file
296
- (file-readable-p tdiary-passwd-file))
297
- (set-buffer buf)
298
- (insert-file-contents tdiary-passwd-file)
299
- (setq tdiary-passwd-cache (read buf)))
470
+ (let ((buf (get-buffer-create "*tdiary-passwd-cache*")))
471
+ (when (and tdiary-passwd-file
472
+ (file-readable-p tdiary-passwd-file))
473
+ (with-current-buffer buf
474
+ (insert-file-contents tdiary-passwd-file)
475
+ (setq tdiary-passwd-cache (read buf)))
300
476
  (kill-buffer buf))))
301
477
 
302
478
  (defun tdiary-passwd-file-save ()
303
479
  "Save password alist.
304
480
  Dangerous!!!"
305
481
  (interactive)
306
- (save-excursion
307
- (let ((buf (get-buffer-create "*tdiary-passwd-cache*")))
308
- (set-buffer buf)
482
+ (let ((buf (get-buffer-create "*tdiary-passwd-cache*")))
483
+ (with-current-buffer buf
309
484
  (erase-buffer)
310
485
  (prin1 tdiary-passwd-cache buf)
311
486
  (terpri buf)
312
487
  (when (and tdiary-passwd-file
313
- (file-writable-p tdiary-passwd-file))
314
- (write-region (point-min) (point-max) tdiary-passwd-file)
315
- (set-file-modes tdiary-passwd-file tdiary-passwd-file-mode))
488
+ (file-writable-p tdiary-passwd-file))
489
+ (write-region (point-min) (point-max) tdiary-passwd-file)
490
+ (set-file-modes tdiary-passwd-file tdiary-passwd-file-mode))
316
491
  (kill-buffer buf))))
317
492
 
318
493
  (defun tdiary-passwd-cache-clear (url)
319
- (setq tdiary-passwd-cache (remassoc url tdiary-passwd-cache)))
494
+ "Clear cached tdairy password of `URL'."
495
+ (setq tdiary-passwd-cache (tdiary-remassoc url tdiary-passwd-cache)))
320
496
 
321
497
  (defun tdiary-passwd-cache-save (url user pass)
498
+ "Save cached username:`USER', password:`PASS', `URL' of diary."
322
499
  (tdiary-passwd-cache-clear url)
323
500
  (add-to-list 'tdiary-passwd-cache
324
- (cons url (cons user (base64-encode-string pass)))))
501
+ (cons url (cons user (base64-encode-string pass)))))
325
502
 
326
503
  (defun tdiary-passwd-cache-read-username (url)
504
+ "Read cached username of the `URL'."
327
505
  (cadr (assoc url tdiary-passwd-cache)))
328
506
 
329
507
  (defun tdiary-passwd-cache-read-password (url)
508
+ "Read cached password of the `URL'."
330
509
  (let ((password (cddr (assoc url tdiary-passwd-cache))))
331
510
  (and password
332
- (base64-decode-string password))))
511
+ (base64-decode-string password))))
333
512
 
334
513
  (defun tdiary-post (mode date data)
514
+ "Post `DATA' as diary of `DATE' with `MODE'. `MODE' is append or replace."
335
515
  (let ((url (concat tdiary-diary-url tdiary-update-rb))
336
- buf title user pass year month day post-data)
516
+ buf title user pass year month day post-data)
337
517
  (when (not (equal mode "edit"))
338
518
  (setq tdiary-edit-mode (setq mode (tdiary-read-mode mode)))
339
519
  (setq tdiary-date (setq date (tdiary-read-date date)))
@@ -341,65 +521,69 @@ Dangerous!!!"
341
521
  (setq user (tdiary-read-username url tdiary-diary-name))
342
522
  (setq pass (tdiary-read-password url tdiary-diary-name))
343
523
  (string-match "\\([0-9][0-9][0-9][0-9]\\)\\([0-9][0-9]\\)\\([0-9][0-9]\\)"
344
- date)
524
+ date)
345
525
  (setq year (match-string 1 date)
346
- month (match-string 2 date)
347
- day (match-string 3 date))
348
- (add-to-list 'post-data (cons "old" date))
349
- (add-to-list 'post-data (cons "year" year))
350
- (add-to-list 'post-data (cons "month" month))
351
- (add-to-list 'post-data (cons "day" day))
352
- (if tdiary-csrf-key (add-to-list 'post-data (cons "csrf_protection_key" tdiary-csrf-key)))
526
+ month (match-string 2 date)
527
+ day (match-string 3 date))
528
+ (push (cons "old" date) post-data)
529
+ (push (cons "year" year) post-data)
530
+ (push (cons "month" month) post-data)
531
+ (push (cons "day" day) post-data)
532
+ (if tdiary-csrf-key (push (cons "csrf_protection_key" tdiary-csrf-key) post-data))
353
533
  (or (equal mode "edit")
354
- (add-to-list 'post-data
355
- (cons "title" (http-url-hexify-string
356
- title
357
- tdiary-coding-system))))
358
- (add-to-list 'post-data (cons mode mode))
534
+ (push (cons "title"
535
+ (tdiary-url-hexify-string
536
+ title
537
+ tdiary-coding-system))
538
+ post-data))
539
+ (push (cons mode mode) post-data)
359
540
  (and data
360
- (add-to-list 'post-data
361
- (cons "body"
362
- (http-url-hexify-string data tdiary-coding-system))))
363
- (setq buf (http-fetch url 'post user pass post-data))
541
+ (push (cons "body"
542
+ (tdiary-url-hexify-string
543
+ data
544
+ tdiary-coding-system))
545
+ post-data))
546
+ (setq buf (tdiary-http-fetch url 'post user pass post-data))
364
547
  (if (bufferp buf)
365
- (save-excursion
366
- (tdiary-passwd-cache-save url user pass)
367
- (set-buffer buf)
368
- (decode-coding-region (point-min) (point-max) tdiary-coding-system)
369
- (goto-char (point-min))
370
- buf)
548
+ (progn
549
+ (tdiary-passwd-cache-save url user pass)
550
+ (set-buffer buf)
551
+ (decode-coding-region (point-min) (point-max) tdiary-coding-system)
552
+ (goto-char (point-min))
553
+ buf)
371
554
  (tdiary-passwd-cache-clear url)
372
- (error "tDiary POST: %s - %s" (car buf) (cdr buf)))))
555
+ (error "The tDiary POST: %s - %s" (car buf) (cdr buf)))))
373
556
 
374
557
  (defun tdiary-post-text ()
375
- (let* ((dirname (expand-file-name tdiary-diary-name
376
- (or tdiary-text-directory
377
- (expand-file-name "~/"))))
378
- (filename (expand-file-name (concat tdiary-date tdiary-text-suffix)
379
- dirname)))
558
+ "Post tDiary data"
559
+ (let* ((site-name (or tdiary-diary-name "default"))
560
+ (base-dir (or tdiary-text-directory (expand-file-name "~/.tdiary-backup/")))
561
+ (dirname (expand-file-name site-name base-dir))
562
+ (filename (expand-file-name (concat tdiary-date tdiary-text-suffix) dirname)))
380
563
  (unless (file-directory-p dirname)
381
564
  (make-directory dirname t)
382
565
  (set-file-modes dirname tdiary-text-directory-mode))
383
566
 
384
567
  ;; If buffer-file-name is tdiary-text-directory/tdiary-diary-name/yyyymmdd.td
385
568
  ;; do nothing.
386
- (unless (equal filename buffer-file-name)
387
- (cond
388
- ((equal tdiary-edit-mode "replace")
389
- (write-region (point-min) (point-max) filename))
390
- ((equal tdiary-edit-mode "append")
391
- (write-region (point-min) (point-max) filename t))))))
569
+ (let ((current-file (and buffer-file-name (expand-file-name buffer-file-name))))
570
+ (unless (equal filename current-file)
571
+ (cond
572
+ ((equal tdiary-edit-mode "replace")
573
+ (write-region (point-min) (point-max) filename))
574
+ ((equal tdiary-edit-mode "append")
575
+ (write-region (point-min) (point-max) filename t)))))))
392
576
 
393
577
  (defun tdiary-update ()
394
578
  "Update diary."
395
579
  (interactive)
396
580
  (unless (and (eq (char-before (point-max)) ?\n)
397
- (eq (char-before (1- (point-max))) ?\n))
581
+ (eq (char-before (1- (point-max))) ?\n))
398
582
  (save-excursion
399
583
  (goto-char (point-max))
400
584
  (insert "\n")))
401
585
  (tdiary-post tdiary-edit-mode tdiary-date
402
- (buffer-substring (point-min) (point-max)))
586
+ (buffer-substring (point-min) (point-max)))
403
587
  (when tdiary-text-save-p
404
588
  (tdiary-post-text))
405
589
  (if buffer-file-name
@@ -408,103 +592,115 @@ Dangerous!!!"
408
592
  (message "SUCCESS")
409
593
  (and (functionp tdiary-browser-function)
410
594
  (funcall tdiary-browser-function
411
- (concat tdiary-diary-url tdiary-index-rb
412
- "?date=" tdiary-date))))
413
-
414
- (defun tdiary-do-replace-entity-ref (from to &optional str)
415
- (save-excursion
416
- (goto-char (point-min))
417
- (if (stringp str)
418
- (progn
419
- (while (string-match from str)
420
- (setq str (replace-match to nil nil str)))
421
- str)
422
- (while (search-forward from nil t)
423
- (replace-match to nil nil)))))
595
+ (concat tdiary-diary-url tdiary-index-rb
596
+ "?date=" tdiary-date))))
424
597
 
425
598
  (defun tdiary-replace-entity-refs (&optional str)
426
599
  "Replace entity references.
427
600
 
428
601
  If STR is a string, replace entity references within the string.
429
602
  Otherwise replace all entity references within current buffer."
430
- (tdiary-do-replace-entity-ref
431
- "&amp;" "&"
432
- (tdiary-do-replace-entity-ref
433
- "&lt;" "<"
434
- (tdiary-do-replace-entity-ref
435
- "&gt;" ">"
436
- (tdiary-do-replace-entity-ref "&quot;" "\"" str)))))
437
-
438
- ;(defun tdiary-read-mode (mode)
439
- ; (let ((default (caar tdiary-edit-mode-list)))
440
- ; (completing-read "Editing mode: " tdiary-edit-mode-list
441
- ; nil t (or mode default) nil default)))
603
+ (let ((entities '(("&amp;" . "&")
604
+ ("&lt;" . "<")
605
+ ("&gt;" . ">")
606
+ ("&quot;" . "\"")
607
+ ("&#39;" . "'")
608
+ ("&#x27;" . "'")
609
+ ("&apos;" . "'"))))
610
+ (if (stringp str)
611
+ (progn
612
+ (dolist (ent entities)
613
+ (setq str (replace-regexp-in-string (regexp-quote (car ent))
614
+ (cdr ent)
615
+ str t t)))
616
+ str)
617
+ (save-excursion
618
+ (dolist (ent entities)
619
+ (goto-char (point-min))
620
+ (while (search-forward (car ent) nil t)
621
+ (replace-match (cdr ent) t t)))))))
442
622
 
623
+ ;; (defun tdiary-read-mode (mode)
624
+ ;; (let ((default (caar tdiary-edit-mode-list)))
625
+ ;; (completing-read "Editing mode: " tdiary-edit-mode-list
626
+ ;; nil t (or mode default) nil default)))
443
627
 
444
628
  (defun tdiary-obsolete-check ()
445
- ;; setting tdiary-diary-url in tdiary-init-file is obsolete.
629
+ "Setting tdiary-diary-url in tdiary-init-file is obsolete."
446
630
  (when tdiary-diary-url
447
631
  (message "tdiary-diary-url is OBSOLETE. Use tdiary-diary-list instead of tdiary-diary-url.")
448
632
  (sit-for 5)))
449
633
 
450
- ;(defun tdiary-setup-diary-url (select-url)
451
- ; (interactive)
452
- ; (if (interactive-p)
453
- ; (setq select-url t))
454
- (defun tdiary-setup-diary-url (select-url)
455
- ;; setting tdiary-diary-url in tdiary-init-file is obsolete.
634
+ ;;;###autoload
635
+ (defun tdiary-setup-diary-url (url)
636
+ "Setting tdiary url:`URL'.
637
+ The tdiary-diary-url in tdiary-init-file is obsolete."
456
638
  (tdiary-obsolete-check)
457
639
  (unless tdiary-diary-url
458
640
  (let* ((selected (car tdiary-diary-list))
459
- (default (car selected)))
460
- (when select-url
461
- (setq selected (assoc (completing-read "Select SITE: " tdiary-diary-list
462
- nil t default nil default)
463
- tdiary-diary-list)))
641
+ (default (car selected)))
642
+ (when url
643
+ (setq selected (assoc (completing-read "Select SITE: " tdiary-diary-list
644
+ nil t default nil default)
645
+ tdiary-diary-list)))
464
646
  (setq tdiary-diary-name (nth 0 selected)
465
- tdiary-diary-url (nth 1 selected))
647
+ tdiary-diary-url (nth 1 selected))
466
648
  (and (eq (length selected) 4)
467
- (setq tdiary-index-rb (nth 2 selected)
468
- tdiary-update-rb (nth 3 selected))))))
469
-
470
- (defun tdiary-new-or-replace (replacep select-url)
471
- (let (buf)
472
- (setq buf (generate-new-buffer "*tdiary tmp*"))
473
- (switch-to-buffer buf)
474
- (tdiary-mode)
649
+ (setq tdiary-index-rb (nth 2 selected)
650
+ tdiary-update-rb (nth 3 selected))))))
651
+
652
+ (defun tdiary--new-or-replace (replacep url)
653
+ (let ((edit-buf (generate-new-buffer "*tdiary tmp*")))
654
+ (switch-to-buffer edit-buf)
655
+ (let ((tdiary--request-url url))
656
+ (tdiary-mode))
475
657
  (setq tdiary-edit-mode "append")
476
- (let (start end body title csrf-key)
477
- (save-excursion
478
- (setq buf (tdiary-post "edit" tdiary-date nil))
479
- (when (bufferp buf)
480
- (save-excursion
481
- (set-buffer buf)
482
- (if (re-search-forward "<input [^>]+name=\"csrf_protection_key\" [^>]*value=\"\\([^>\"]*\\)\">" nil t nil)
483
- (setq csrf-key (match-string 1)))
484
- (re-search-forward "<input [^>]+name=\"title\" [^>]+value=\"\\([^>\"]*\\)\">" nil t nil)
485
- (setq title (match-string 1))
486
- (re-search-forward "<textarea [^>]+>" nil t nil)
487
- (setq start (match-end 0))
488
- (re-search-forward "</textarea>" nil t nil)
489
- (setq end (match-beginning 0))
490
- (setq body (buffer-substring start end))
491
- )
492
- (setq tdiary-csrf-key (and csrf-key (tdiary-replace-entity-refs csrf-key)))
493
- (when replacep
494
- (insert body)
495
- (setq tdiary-edit-mode "replace")
496
- (setq tdiary-title (tdiary-replace-entity-refs title))
497
- (goto-char (point-min))
498
- (tdiary-replace-entity-refs)
499
- (set-buffer-modified-p nil)))))))
500
-
501
- (defun tdiary-new (&optional select-url)
658
+ (let (start body title csrf-key http-buf)
659
+ (setq http-buf (tdiary-post "edit" tdiary-date nil))
660
+ (when (bufferp http-buf)
661
+ (with-current-buffer http-buf
662
+ (let ((case-fold-search t))
663
+ (goto-char (point-min))
664
+ (when (re-search-forward "name=[\"']csrf_protection_key[\"'][^>]*value=[\"']\\([^\"']*\\)[\"']" nil t)
665
+ (setq csrf-key (match-string 1)))
666
+ (goto-char (point-min))
667
+ (when (re-search-forward "name=[\"']title[\"'][^>]*value=[\"']\\([^\"']*\\)[\"']" nil t)
668
+ (setq title (match-string 1)))
669
+ (goto-char (point-min))
670
+ (if (re-search-forward "<textarea[^>]*>" nil t)
671
+ (progn
672
+ (setq start (match-end 0))
673
+ (if (re-search-forward "</textarea>" nil t)
674
+ (setq body (buffer-substring start (match-beginning 0)))
675
+ (setq body "")))
676
+ (setq body ""))))
677
+ (with-current-buffer edit-buf
678
+ (setq tdiary-csrf-key (and csrf-key (tdiary-replace-entity-refs csrf-key)))
679
+ (when replacep
680
+ (if (and (stringp body) (> (length body) 0))
681
+ (insert body)
682
+ ;; (insert "【デバッグ出力:抽出失敗】\n")
683
+ )
684
+ (setq tdiary-edit-mode "replace")
685
+ (when title
686
+ (setq tdiary-title (tdiary-replace-entity-refs title)))
687
+ (goto-char (point-min))
688
+ (tdiary-replace-entity-refs)
689
+ (if (and tdiary-text-save-p buffer-file-name)
690
+ (save-buffer)
691
+ (set-buffer-modified-p nil))))))))
692
+
693
+ ;;;###autoload
694
+ (defun tdiary-new (&optional url)
695
+ "Create New diary of URL:`URL'."
502
696
  (interactive "P")
503
- (tdiary-new-or-replace nil select-url))
697
+ (tdiary--new-or-replace nil url))
504
698
 
505
- (defun tdiary-replace (&optional select-url)
699
+ ;;;###autoload
700
+ (defun tdiary-replace (&optional url)
701
+ "Replace New diary of URL:`URL'."
506
702
  (interactive "P")
507
- (tdiary-new-or-replace t select-url))
703
+ (tdiary--new-or-replace t url))
508
704
 
509
705
  (defvar tdiary-mode-map (make-sparse-keymap)
510
706
  "Set up keymap for tdiary-mode.
@@ -524,26 +720,27 @@ If you want to set up your own key bindings, use `tdiary-mode-hook'.")
524
720
  (load init-file t t))))
525
721
 
526
722
  (defun tdiary-make-temp-file-name ()
527
- (let ((tmpdir (expand-file-name tdiary-diary-name
528
- (expand-file-name (user-login-name)
529
- temporary-file-directory))))
530
- (unless (file-directory-p tmpdir)
531
- (make-directory tmpdir t)
532
- (set-file-modes tmpdir tdiary-text-directory-mode))
533
- (expand-file-name tdiary-date tmpdir)))
723
+ "Get the local backup file name for the diary (bypassing /tmp/)."
724
+ (let* ((site-name (or tdiary-diary-name "default"))
725
+ (base-dir (or tdiary-text-directory (expand-file-name "~/.tdiary-backup/")))
726
+ (dirname (expand-file-name site-name base-dir)))
727
+ (unless (file-directory-p dirname)
728
+ (make-directory dirname t)
729
+ (set-file-modes dirname tdiary-text-directory-mode))
730
+ (expand-file-name (concat tdiary-date tdiary-text-suffix) dirname)))
534
731
 
535
732
  (defun tdiary-html-mode-init ()
536
- "Initialize tDiary for default style"
733
+ "Initialize tDiary for default style."
537
734
  (tdiary-tempo-define (append tdiary-plugin-initial-definition
538
- tdiary-plugin-definition))
735
+ tdiary-plugin-definition))
539
736
  (tempo-use-tag-list 'tdiary-tempo-tags tdiary-completion-finder))
540
737
 
541
738
  (defun tdiary-rd-mode-init ()
542
- "Initialize tDiary for RD style"
739
+ "Initialize tDiary for RD style."
543
740
  )
544
741
 
545
742
  (defun tdiary-mode ()
546
- "tDiary editing mode.
743
+ "The tDiary editing mode.
547
744
  The value of `tdiary-style-mode' will be used as actual major mode.
548
745
 
549
746
  \\{tdiary-mode-map}"
@@ -556,7 +753,7 @@ The value of `tdiary-style-mode' will be used as actual major mode.
556
753
  (defun tdiary-mode-setup ()
557
754
  "Set tDiary mode up."
558
755
  (interactive)
559
- (make-local-variable 'require-final-newline)
756
+ (make-local-variable 'require-final-newline)
560
757
  (make-local-variable 'tdiary-date)
561
758
  (make-local-variable 'tdiary-title)
562
759
  (make-local-variable 'tdiary-edit-mode)
@@ -565,49 +762,45 @@ The value of `tdiary-style-mode' will be used as actual major mode.
565
762
  (make-local-variable 'tdiary-update-rb)
566
763
  (make-local-variable 'tdiary-csrf-key)
567
764
  (setq require-final-newline t
568
- indent-tabs-mode nil
569
- tdiary-edit-mode "replace"
570
- tdiary-date (format-time-string "%Y%m%d" (tdiary-today)))
571
-
765
+ indent-tabs-mode nil
766
+ tdiary-edit-mode "replace"
767
+ tdiary-date (format-time-string "%Y%m%d" (tdiary-today)))
572
768
  (tdiary-load-init-file)
573
-
574
- (tdiary-setup-diary-url (if (boundp 'select-url)
575
- select-url
576
- t))
577
-
769
+ (tdiary-setup-diary-url (if (eq tdiary--request-url 'unboundq)
770
+ select-url
771
+ t))
578
772
  (set-buffer-file-coding-system tdiary-coding-system)
579
-
580
773
  (or tdiary-passwd-cache
581
774
  (tdiary-passwd-file-load))
582
-
583
775
  (if buffer-file-name
584
776
  (let ((buf-name (file-name-nondirectory buffer-file-name)))
585
- (when (string-match
586
- "\\([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\\)"
587
- buf-name)
588
- (setq tdiary-date (match-string 1 buf-name))))
777
+ (when (string-match
778
+ "\\([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\\)"
779
+ buf-name)
780
+ (setq tdiary-date (match-string 1 buf-name))))
589
781
  (setq tdiary-date (tdiary-read-date nil))
590
782
  (if tdiary-text-save-p
591
- (set-visited-file-name (tdiary-make-temp-file-name))
783
+ (unless buffer-file-name
784
+ (let ((change-major-mode-with-file-name nil))
785
+ (set-visited-file-name (tdiary-make-temp-file-name))))
592
786
  (unless (string= (buffer-name) tdiary-date)
593
- (rename-buffer tdiary-date t))))
594
-
787
+ (rename-buffer tdiary-date t))))
595
788
  (let ((init (intern (concat "tdiary-" (symbol-name tdiary-style-mode) "-init"))))
596
789
  (if (fboundp init) (funcall init)))
597
-
598
790
  (run-hooks 'tdiary-mode-hook))
599
791
 
600
792
  (defun tdiary-mode-toggle (&optional arg)
793
+ "Toggle tdiary-mode via `ARG'."
601
794
  (interactive "P")
602
795
  (let ((in-tdiary (and (boundp 'tdiary-date) tdiary-date)))
603
796
  (cond ((not arg)
604
- (setq arg (not in-tdiary)))
605
- ((or (eq arg '-) (and (numberp arg) (< arg 0)))
606
- (setq arg nil)))
797
+ (setq arg (not in-tdiary)))
798
+ ((or (eq arg '-) (and (numberp arg) (< arg 0)))
799
+ (setq arg nil)))
607
800
  (cond (arg
608
- (tdiary-mode-setup))
609
- (in-tdiary
610
- (setq tdiary-date nil)))))
801
+ (tdiary-mode-setup))
802
+ (in-tdiary
803
+ (setq tdiary-date nil)))))
611
804
 
612
805
  (provide 'tdiary-mode)
613
806
  ;;; tdiary-mode.el ends here