-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathend-it-1.20.el
88 lines (78 loc) · 3.13 KB
/
end-it-1.20.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
;;; end-it.el --- Add an "ends here" marker to a file -*- lexical-binding: t -*-
;; Copyright 2018-2024 by Dave Pearson <[email protected]>
;; Author: Dave Pearson <[email protected]>
;; Version: 1.20
;; Keywords: convenience
;; URL: https://github.com/davep/end-it.el
;; Package-Requires: ((emacs "24"))
;; This program is free software: you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by the
;; Free Software Foundation, either version 3 of the License, or (at your
;; option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
;; Public License for more details.
;;
;; You should have received a copy of the GNU General Public License along
;; with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; end-it.el is a simple tool that provides a command for quickly adding a
;; "foo.xxx ends here" marker to the end of the current buffer. The format
;; used to add it takes into account the language in use and attempts to use
;; the correct comment style.
;;; Code:
(defun end-it--format ()
"Return the correct `end-it' format for the current buffer."
(cond ((derived-mode-p 'lisp-mode 'emacs-lisp-mode 'clojure-mode 'scheme-mode)
";;; %s")
((derived-mode-p 'python-mode 'ruby-mode 'makefile-gmake-mode
'makefile-bsdmake-mode 'sh-mode 'restclient-mode
'conf-mode 'yaml-mode 'dockerfile-mode 'perl-mode
'gitconfig-mode 'julia-mode 'fish-mode)
"### %s")
((derived-mode-p 'c-mode 'css-mode 'js-mode)
"/* %s */")
((derived-mode-p 'rust-mode 'zig-mode 'swift-mode)
"// %s")
((derived-mode-p 'org-mode)
"# %s")
((derived-mode-p 'markdown-mode)
"[//]: # (%s)")
((derived-mode-p 'web-mode)
(cond ((string= (symbol-value 'web-mode-engine) "django")
"{# %s #}")
(t
"<!-- %s -->")))
((derived-mode-p 'haskell-mode)
"-- %s")
(t
"%s")))
(defun end-it--previous-line-empty-p ()
"Is the line before this one empty?"
(save-excursion
(beginning-of-line)
(forward-line -1)
(eolp)))
;;;###autoload
(defun end-it ()
"Add a end-of-file marker to the current buffer.
As a side effect `point' will be moved to the end of the
buffer (this is a deliberate design decision, as I want to be
able to see that the addition worked okay and makes sense)."
(interactive "*")
(if (buffer-file-name)
(let ((file (file-name-nondirectory (buffer-file-name)))
(format (end-it--format)))
(goto-char (point-max))
(unless (bolp)
(insert "\n"))
(unless (end-it--previous-line-empty-p)
(insert "\n"))
(insert (format format (format "%s %s" file "ends here")))
(insert "\n"))
(error "It only makes sense to end-it in buffers that are related to a file")))
(provide 'end-it)
;;; end-it.el ends here