daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (when (autoload-if-found
  2.        '(appt my-org-agenda-to-appt ad:appt-display-message
  3.               ad:appt-disp-window)
  4.        "appt" nil t)
  5.  
  6.   (with-eval-after-load "postpone"
  7.     (global-set-key (kbd "C-c f 3") #'my-org-agenda-to-appt))
  8.  
  9.   (with-eval-after-load "appt"
  10.     ;; window を フレーム内に表示する
  11.     (setq appt-display-format 'echo)
  12.  
  13.     ;; window を継続表示する時間[s]
  14.     (setq appt-display-duration 5)
  15.  
  16.     ;; ビープ音の有無
  17.     (setq appt-audible nil)
  18.  
  19.     ;; 何分前から警告表示を開始するか[m]
  20.     (setq appt-message-warning-time 20)
  21.  
  22.     ;; 警告表示開始から何分ごとにリマインドするか[m]
  23.     (setq appt-display-interval 1)
  24.  
  25.     ;; appt-display-format が 'echo でも appt-disp-window-function を呼ぶ
  26.     (defun ad:appt-display-message (string mins)
  27.       "Display a reminder about an appointment.
  28. The string STRING describes the appointment, due in integer MINS minutes.
  29. The arguments may also be lists, where each element relates to a
  30. separate appointment.  The variable `appt-display-format' controls
  31. the format of the visible reminder.  If `appt-audible' is non-nil,
  32. also calls `beep' for an audible reminder."
  33.       (if appt-audible (beep 1))
  34.       ;; Backwards compatibility: avoid passing lists to a-d-w-f if not necessary.
  35.       (and (listp mins)
  36.            (= (length mins) 1)
  37.            (setq mins (car mins)
  38.                  string (car string)))
  39.       (when (memq appt-display-format '(window echo))
  40.         (let ((time (format-time-string "%a %b %e "))
  41.               err)
  42.           (condition-case err
  43.               (funcall appt-disp-window-function
  44.                        (if (listp mins)
  45.                            (mapcar 'number-to-string mins)
  46.                          (number-to-string mins))
  47.                        time string)
  48.             (wrong-type-argument
  49.              (if (not (listp mins))
  50.                  (signal (car err) (cdr err))
  51.                (message "Argtype error in `appt-disp-window-function' - \
  52. update it for multiple appts?")
  53.                ;; Fallback to just displaying the first appt, as we used to.
  54.                (funcall appt-disp-window-function
  55.                         (number-to-string (car mins)) time
  56.                         (car string)))))
  57.           err))
  58.       (cond ((eq appt-display-format 'window)
  59.              ;; TODO use calendar-month-abbrev-array rather than %b?
  60.              (run-at-time (format "%d sec" appt-display-duration)
  61.                           nil
  62.                           appt-delete-window-function))
  63.             ((eq appt-display-format 'echo)
  64.              (message "%s" (if (listp string)
  65.                                (mapconcat 'identity string "\n")
  66.                              string)))))
  67.     (advice-add 'appt-display-message :override #'ad:appt-display-message)
  68.  
  69.     (defun ad:appt-disp-window (min-to-app _new-time appt-msg)
  70.       "Extension to support appt-disp-window."
  71.       (if (string= min-to-app "0")
  72.           (my-desktop-notification "### Expired! ###" appt-msg t "Glass")
  73.         (my-desktop-notification
  74.          (concat "in " min-to-app " min.") appt-msg nil "Tink")))
  75.     (cond
  76.      ((eq appt-display-format 'echo)
  77.       (setq appt-disp-window-function 'ad:appt-disp-window))
  78.      ((eq appt-display-format 'window)
  79.       (advice-add 'appt-disp-window :before #'ad:appt-disp-window))))
  80.  
  81.   (with-eval-after-load "org"
  82.     ;; アジェンダを開いたらアラームリストを更新して有効化する
  83.     (unless noninteractive
  84.       (add-hook 'org-agenda-mode-hook #'my-org-agenda-to-appt) ;; init
  85.       (appt-activate 1))
  86.     ;; 重複実行の抑制用フラグ
  87.     (defvar my-org-agenda-to-appt-ready t)
  88.     ;; org-agenda の内容をアラームに登録する
  89.     (defun my-org-agenda-to-appt ()
  90.       "Update `appt-time-mag-list'.  Use `async' if possible."
  91.       (interactive)
  92.       (if (not (require 'async nil t))
  93.           (org-agenda-to-appt t '((headline "TODO")))
  94.         (when my-org-agenda-to-appt-ready
  95.           (setq my-org-agenda-to-appt-ready nil)
  96.           (async-start
  97.            `(lambda ()
  98.               (setq org-agenda-files ',org-agenda-files)
  99.               (org-agenda-to-appt t '((headline "TODO")))
  100.               appt-time-msg-list)
  101.            (lambda (result)
  102.              (setq appt-time-msg-list result)
  103.              (let ((cnt (length appt-time-msg-list)))
  104.                (if (eq cnt 0)
  105.                    (message "No event to add")
  106.                  (message "Added %d event%s for today"
  107.                           cnt (if (> cnt 1) "s" ""))))
  108.              (setq my-org-agenda-to-appt-ready t))))))
  109.     ;; 定期的に更新する
  110.     (run-with-idle-timer 500 t 'my-org-agenda-to-appt)
  111.     ;; キャプチャ直後に更新
  112.     (add-hook 'org-capture-before-finalize-hook #'my-org-agenda-to-appt))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top