| 269 | | "ディレクトリ配置をセットアップする。") |
| | 269 | (interactive) |
| | 270 | "ディレクトリ配置をセットアップする。" |
| | 271 | |
| | 272 | (and |
| | 273 | ;; simple-hatena-bin |
| | 274 | (simple-hatena-setup-hatena-bin-executable-p) |
| | 275 | |
| | 276 | ;; hatena id(s) |
| | 277 | (simple-hatena-setup-id))) |
| | 278 | |
| | 279 | (defun simple-hatena-setup-hatena-bin-executable-p () |
| | 280 | (if (file-executable-p simple-hatena-bin) |
| | 281 | t |
| | 282 | (progn |
| | 283 | (when (y-or-n-p |
| | 284 | (format |
| | 285 | (concat |
| | 286 | "Please download and/or setup `はてなダイアリーライター'.\n" |
| | 287 | " open a webpage? ") |
| | 288 | simple-hatena-bin)) |
| | 289 | (browse-url "http://coderepos.org/share/wiki/SimpleHatenaMode")) |
| | 290 | (message "Without forgetting the rerun of the simple-hatena-setup.") |
| | 291 | (read-char) ;; wait user input. |
| | 292 | nil))) |
| | 293 | |
| | 294 | (defun simple-hatena-setup-id () |
| | 295 | (let |
| | 296 | ((ids (list))) |
| | 297 | |
| | 298 | (when (file-directory-p simple-hatena-root) |
| | 299 | (dolist (id (simple-hatena-internal-list-directories simple-hatena-root)) |
| | 300 | (add-to-list 'ids id))) |
| | 301 | |
| | 302 | (when simple-hatena-default-id |
| | 303 | (add-to-list 'ids simple-hatena-default-id)) |
| | 304 | |
| | 305 | (when (eq (length ids) 0) |
| | 306 | (add-to-list 'ids (read-string "Please input your default Hatena id: "))) |
| | 307 | |
| | 308 | (while (y-or-n-p |
| | 309 | (format |
| | 310 | "id `%s' found.\nsetup other id(s)? " |
| | 311 | (mapconcat 'identity |
| | 312 | ids "', `"))) |
| | 313 | (add-to-list 'ids (read-string "Please input your other Hatena id: "))) |
| | 314 | |
| | 315 | (dolist (id ids) |
| | 316 | (simple-hatena-setup-id-create-directory-and-file id)))) |
| | 317 | |
| | 318 | (defun simple-hatena-setup-id-create-directory-and-file (id) |
| | 319 | (simple-hatena-setup-create-directory-and-file |
| | 320 | (expand-file-name |
| | 321 | (format "%s/%s/diary/config.txt" |
| | 322 | simple-hatena-root id)))) |
| | 323 | |
| | 324 | (defun simple-hatena-setup-create-directory-and-file (filename) |
| | 325 | "setup adirectory and a file. |
| | 326 | NOTE: Create intermediate directories as required." |
| | 327 | (let |
| | 328 | ((dirname (file-name-directory filename))) |
| | 329 | (unless (file-exists-p filename) |
| | 330 | (unless (file-directory-p dirname) |
| | 331 | (make-directory dirname 'parents)) |
| | 332 | (append-to-file 1 1 filename)))) |