summary refs log tree commit diff stats
path: root/lisp/+crux.el
blob: c55a0b9963768a90062583fcde3f8cdfe46728b5 (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
49
50
51
52
53
54
55
56
57
58
;;; +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))))))

(defun +crux-kill-and-join-forward (&optional arg)
  "If at end of line, join with following; else (visual)-kill line.
In `visual-line-mode', runs command `kill-visual-line'; in other
modes, runs command `kill-line'.  Passes ARG to command when
provided.  Deletes whitespace at join."
  (interactive "P")
  (if (and (eolp) (not (bolp)))
      (delete-indentation 1)
    (funcall (if visual-line-mode #'kill-visual-line #'kill-line) arg)))

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