logpad.el

Check-in [18a7a79210]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:transferred to Fossil
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA3-256: 18a7a79210978a64601c6d868489f44e858d55992e11986f0449fcdc394577fb
User & Date: Cthulhux 2019-09-27 20:43:24
Context
2019-09-27
20:43
transferred to Fossil Leaf check-in: 18a7a79210 user: Cthulhux tags: trunk
20:42
initial empty check-in check-in: 8a776ce80c user: Cthulhux tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added README.md.



























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# logpad.el [![MELPA](https://melpa.org/packages/logpad-badge.svg)](https://melpa.org/#/logpad)

That one Notepad feature - for GNU Emacs.

## Huh?

A couple of years ago, I wrote [a plug-in](https://www.vim.org/scripts/script.php?script_id=2775) that would allow me to use Microsoft's [Notepad logging](https://www.howtogeek.com/258545/how-to-use-notepad-to-create-a-dated-log-or-journal-file/) from inside Vim. This is the GNU Emacs variant.

## Installation

`logpad.el` is available on [MELPA](https://melpa.org/#/logpad).

## Usage

Enable `(logpad-mode)` and GNU Emacs will check for the magic `.LOG` line whenever you open a text file. For your convenience, this is only happening for new buffers, existing buffers won't be touched.

## Donations (optional)

`logpad.el` is free software by the terms of the [WTFPL](http://www.wtfpl.net/txt/copying/). As some people - including myself - like to contribute money for a good cause anyway, here are two possible options for you:

### Donate money to the nature:

Both [Kākāpō Recovery](http://kakaporecovery.org.nz/) and the [WWF](https://support.wwf.org.uk/adopt-a-panda) do a pretty good job at trying to keep species alive. You are invited to join their efforts.

### Donate money to me:

Yes, I like money as well.

[![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/GebtmireuerGeld/)

Added logpad.el.













































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
;;; logpad.el --- Simulate Windows Notepad for logging. -*- lexical-binding: t; -*-

;; Copyright (C) 2018 Jens K. Loewe

;; Author: Jens K. Loewe <git@tuxproject.de>
;; URL: https://bitbucket.org/tux_/logpad.el
;; Keywords: files outlines notepad
;; Version: 1.0.1

;; This work is free. You can redistribute it and/or modify it under the
;; terms of the Do What The Fuck You Want To Public License, Version 2,
;; as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.

;; This file is NOT part of GNU Emacs.

;;; Commentary:

;; This minor mode transfers the logging mechanisms of Windows Notepad
;; to GNU Emacs.  It will be enabled whenever you open a text file which
;; starts with ".LOG".

;;; Code:

;; --------------------
;; Configuration stuff:
;; --------------------


(defgroup logpad nil
  "Customize the Notepad logging simulation."
  :prefix "logpad-"
  :group 'text)


(defcustom logpad-add-newlines nil
  "When non-nil additional newlines are added for look-and-feel reasons.
Set this to nil if you want the original Notepad behavior of not having newlines."
  :type 'boolean)


(defcustom logpad-add-to-end t
  "If set to true, new log entries will be added to the end of the file.
Otherwise, they will be added right below the .LOG line."
  :type 'boolean)


;; ------------
;; Actual code:
;; ------------


(defun logpad--get-nth-line (number)
  "Return the NUMBERth line in the current buffer."
  (save-restriction
    (widen)
    (save-excursion
      (with-no-warnings
        (goto-line number))
      (buffer-substring-no-properties (line-beginning-position)
                                      (line-end-position)))))


(defun logpad--insert-date ()
  "Insert the current date/time."
  (insert (format-time-string "%c")))


(defun logpad--newline-with-jump ()
  "Add a new line to the end of wherever we are and go there."
  (end-of-line)
  (open-line 1)
  (forward-line))


(defun logpad--enable-logging ()
  "This is where the magic happens."
  ;; This will move the user's cursor.
  ;; This is to be expected, after all.
  (unless (local-variable-p 'logpad-done)
    ;; Do it once only.
    (setq-local logpad-done t)

    (with-no-warnings
      (if logpad-add-to-end
          ;; Add a new entry to the end of the file.
          (goto-char (point-max))

        ;; Add a new entry after the first line.
        (goto-line 1))
      (logpad--newline-with-jump)
      (when logpad-add-newlines
        (logpad--newline-with-jump)) ;; Leave one empty line before the new date.
      (logpad--insert-date)
      (logpad--newline-with-jump))

    (message "Logpad applied to '%s'." (buffer-name))))


(defun logpad--check-for-log ()
  "Try to determine whether the current file is a log file."
  (when (and
         (bound-and-true-p logpad-mode)
         (string= (logpad--get-nth-line 1) ".LOG"))
    ;; Perform the magic.
    (logpad--enable-logging)))


;;;###autoload
(define-minor-mode logpad-mode
  "Simulate Windows Notepad for logging."
  :after-hook (add-hook 'text-mode-hook (lambda () (logpad--check-for-log)))
  :global t
  :init-value nil
  :lighter " Logpad")


(provide 'logpad)
;;; logpad.el ends here