summary refs log tree commit diff stats
path: root/lisp/+crux.el
blob: 45b4dee3087fb74c0bbb0a880cadd7b7806e936f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
;;; +crux.el -*- lexical-binding: t; -*-

;;; Code:

(require 'crux)

(defgroup +crux nil
  "Extra crux customizations."
  :group 'crux
  :prefix "+crux-")

(defun +crux-kill-ring-save (begin end arg)
  "Copy region to the kill-ring, possibly indenting it first.
Copy from BEGIN to END using `kill-ring-save' if no argument was
passed, or with `crux-indent-rigidly-and-copy-to-clipboard' if
one was."
  (interactive "r\nP")
  (call-interactively (if arg
                          #'crux-indent-rigidly-and-copy-to-clipboard
                        #'kill-ring-save))
  (pulse-momentary-highlight-region begin end))

(defcustom +crux-default-date-format "%c"
  "Default date format to use for `+crux-insert-date-or-time'.
Should be a format parsable by `format-time-string'."
  :type 'string)

(defcustom +crux-alternate-date-format "%FT%T%z"
  "Alternate date format to use for `+crux-insert-date-or-time'.
Should be a format parsable by `format-time-string'."
  :type 'string)

(defun +crux-insert-date-or-time (arg)
  "Insert current date or time.
Called without a prefix ARG, insert the time formatted by
`+crux-default-date-format'.  When called with \\[universal-argument],
format the time with `+crux-alternate-date-format'.  Otherwise,
prompt for the time format."
  (interactive "*P")
  (let ((time (current-time)))
    (insert (cond
             ((null arg) (format-time-string +crux-default-date-format time))
             ((eq (car-safe arg) 4)
              (format-time-string +crux-alternate-date-format time))
             (t (format-time-string (read-string "Time Format: ") time))))))

(provide '+crux)
;;; +crux.el ends here