summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/km-denote.el70
-rw-r--r--lisp/km-files.el13
-rw-r--r--lisp/km-god.el36
-rw-r--r--lisp/km-magit.el34
-rw-r--r--lisp/km-mail.el2
-rw-r--r--lisp/km-org-agenda.el2
-rw-r--r--lisp/km-org.el10
-rw-r--r--lisp/km-python.el60
8 files changed, 111 insertions, 116 deletions
diff --git a/lisp/km-denote.el b/lisp/km-denote.el
new file mode 100644
index 0000000..24e98d2
--- /dev/null
+++ b/lisp/km-denote.el
@@ -0,0 +1,70 @@
+;;; km-denote.el --- Denote-related extensions -*- lexical-binding: t; -*-
+
+;; Copyright Kyle Meyer <kyle@kyleam.com>
+
+;; Author: Kyle Meyer <kyle@kyleam.com>
+;; URL: https://git.kyleam.com/emacs.d
+
+;; 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/>.
+
+;;; Code:
+
+(require 'denote)
+
+;;;###autoload
+(defun km/denote-add-frontmatter ()
+ "Insert front matter into current file.
+Unlike an interactive call to `denote-add-front-matter', this
+does not prompt for the title and keywords; it just takes them
+from the file name."
+ (interactive)
+ (let ((fname (or (buffer-file-name)
+ (user-error "Buffer not visiting file"))))
+ (denote-add-front-matter
+ fname
+ (denote-retrieve-filename-title fname)
+ (denote-extract-keywords-from-path fname))))
+
+;;;###autoload
+(defun km/denote-find-file-at-point ()
+ "Find the file in `denote-directory' for the denote ID at point.
+The file must be tracked in Git."
+ (interactive)
+ (let ((id (save-excursion
+ (let ((case-fold-search nil))
+ (skip-chars-backward "-a-z0-9_T"))
+ (if (looking-at denote-id-regexp)
+ (match-string-no-properties 0)
+ (user-error "No denote ID at point"))))
+ (default-directory denote-directory))
+ (find-file
+ (car (or (process-lines "git" "ls-files" "--" (concat id "--*"))
+ (process-lines "git" "ls-files" "--" (concat "**/" id "--*"))
+ (user-error "No tracked file found for %s" id))))))
+
+(defun km/denote-insert-id (&optional with-prefix)
+ "Insert ID of tracked file in `denote-directory'.
+When WITH-PREFIX is non-nil, prepend \"denote:\" to the inserted
+ID."
+ (interactive "P")
+ (let* ((default-directory denote-directory)
+ (id (or (denote-extract-id-from-string
+ (completing-read
+ "Note: "
+ (process-lines "git" "ls-files" "--" "*--*")))
+ (error "Could not determine ID"))))
+ (insert (concat (and with-prefix "denote:") id))))
+
+(provide 'km-denote)
+;;; km-denote.el ends here
diff --git a/lisp/km-files.el b/lisp/km-files.el
index 9e9edc3..5ec4a06 100644
--- a/lisp/km-files.el
+++ b/lisp/km-files.el
@@ -99,6 +99,14 @@ Use the current file name as initial input of prompt."
(defun km/read-recent-file ()
(completing-read "Choose recent file: " recentf-list nil t))
+;;;###autoload
+(defun km/find-file-with-denote-naming (file)
+ (interactive "F")
+ (find-file
+ (concat (file-name-directory file)
+ (format-time-string "%Y%m%dT%H%M%S--")
+ (file-name-nondirectory file))))
+
;;; Scratch files
@@ -125,7 +133,7 @@ Prompt with characters from `km/find-scratch-buffers' to
determine the extension of the scratch file.
With prefix argument PWD, find the scratch file in
-`default-directory' instead of /tmp."
+`default-directory' instead of `temporary-file-directory'."
(interactive "P")
(switch-to-buffer (km/scratch--find-file-no-select pwd)))
@@ -142,7 +150,8 @@ With prefix argument PWD, find the scratch file in
(let* ((choices (mapcar #'car km/find-scratch-buffers))
(ch (read-char-choice (concat "[" choices "]") choices))
(ext (cadr (assq ch km/find-scratch-buffers))))
- (concat (if pwd default-directory "/tmp/") "scratch" ext)))
+ (expand-file-name (concat "scratch" ext)
+ (if pwd default-directory temporary-file-directory))))
(provide 'km-files)
;;; km-files.el ends here
diff --git a/lisp/km-god.el b/lisp/km-god.el
deleted file mode 100644
index 4d741b4..0000000
--- a/lisp/km-god.el
+++ /dev/null
@@ -1,36 +0,0 @@
-;;; km-god.el --- God mode extensions
-
-;; Copyright Kyle Meyer <kyle@kyleam.com>
-
-;; Author: Kyle Meyer <kyle@kyleam.com>
-;; URL: https://git.kyleam.com/emacs.d
-
-;; 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/>.
-
-;;; Code:
-
-(require 'god-mode)
-
-(defun km/god-update-cursor ()
- (setq cursor-type (if god-local-mode 'bar 'box)))
-
-(defun km/god-gnus-p ()
- "Return non-nil if a Gnus-related mode is enabled."
- (derived-mode-p 'gnus-group-mode
- 'gnus-summary-mode
- 'gnus-article-mode
- 'message-mode))
-
-(provide 'km-god)
-;;; km-god.el ends here
diff --git a/lisp/km-magit.el b/lisp/km-magit.el
index 3dd433c..204bddb 100644
--- a/lisp/km-magit.el
+++ b/lisp/km-magit.el
@@ -50,19 +50,21 @@ a proper commit."
(interactive)
(magit-run-git "commit" "--all" "--message=auto"))
-(defun km/magit-update-or-auto-commit (&optional no-directory)
+(defun km/magit-update-or-auto-commit (&optional full-name)
(interactive "P")
(let ((files (delete-dups (nconc (magit-unstaged-files)
(magit-staged-files)))))
(cl-case (length files)
(0 (user-error "No tracked files with changes"))
(1
- (magit-run-git "commit" "--all" "--message"
- (concat (funcall (if no-directory
- #'file-name-nondirectory
- #'identity)
- (car files))
- ": Update")))
+ (let ((file (car files)))
+ (magit-run-git "commit" "--all" "--message"
+ (concat (funcall (if full-name
+ #'identity
+ #'file-name-nondirectory)
+ file)
+ (and (magit-rev-verify (concat "HEAD:" file))
+ ": Update")))))
(t
(km/magit-auto-commit)))))
@@ -255,7 +257,7 @@ argument SUFFIX, prompt for a suffix to use instead of
(list
(magit-completing-read
"Branch to archive" (magit-list-refnames "refs/heads")
- nil 'require nil nil
+ nil 'require-match nil nil
(or (magit-branch-at-point) (magit-get-previous-branch)))))))
(setq branches
(mapcar (lambda (branch)
@@ -320,7 +322,7 @@ argument SUFFIX, prompt for a suffix to use instead of
(interactive
(list (magit-completing-read
"Delete set with member" (magit-list-refnames "refs/heads")
- nil 'require nil nil
+ nil 'require-match nil nil
(or (magit-branch-at-point) (magit-get-previous-branch)))))
(km/magit-branch--set-action
"Delete"
@@ -332,7 +334,7 @@ argument SUFFIX, prompt for a suffix to use instead of
(interactive
(list (magit-completing-read
"Archive set with member" (magit-list-refnames "refs/heads")
- nil 'require nil nil
+ nil 'require-match nil nil
(or (magit-branch-at-point) (magit-get-previous-branch)))))
(km/magit-branch--set-action
"Archive"
@@ -467,13 +469,13 @@ N defaults to 20."
(1 (car files))
(t (magit-completing-read "File" files nil t))))))
-(defun km/magit-insert-staged-file (&optional no-directory)
+(defun km/magit-insert-staged-file (&optional full-name)
"Select a staged file to insert.
This is useful for referring to file names in commit messages.
By default, the path for the file name is relative to the top
directory of the repository. Remove the directory component from
-the file name if NO-DIRECTORY is non-nil.
+the file name unless FULL-NAME is non-nil.
If there are no staged files, look instead at files that changed
in HEAD. These rules will usually offer the files of interest
@@ -489,7 +491,7 @@ command will still offer the staged files)."
(0 (error "No files found"))
(t
(completing-read "Staged file: " files nil t)))))
- (insert (if no-directory (file-name-nondirectory file) file)))))
+ (insert (if full-name file (file-name-nondirectory file))))))
(defun km/magit-shorten-hash (hash &optional n)
(magit-rev-parse (format "--short=%s" (or n (magit-abbrev-length))) hash))
@@ -546,7 +548,7 @@ argument."
(defun km/magit-rev-ancestor-p (rev-a rev-b)
"Report whether REV-A is an ancestor of REV-B."
(interactive
- (let* ((rev-a (magit-read-branch-or-commit "Ancestor candidate")))
+ (let ((rev-a (magit-read-branch-or-commit "Ancestor candidate")))
(list rev-a (magit-read-other-branch-or-commit
(format "Is %s an ancestor of" rev-a)
rev-a))))
@@ -1141,8 +1143,8 @@ function."
;; This always converts to commits IDs. It could try to map
;; refnames to the appropriate GitHub link (including remotes
;; to forks), but I don't have much need for it at the moment.
- (let ((rev1 (magit-rev-parse (match-string 1 magit-buffer-range)))
- (rev2 (magit-rev-parse (match-string 3 magit-buffer-range))))
+ (let ((rev1 (magit-commit-p (match-string 1 magit-buffer-range)))
+ (rev2 (magit-commit-p (match-string 3 magit-buffer-range))))
(format "%s/compare/%s...%s"
(or (km/magit-github-url) "")
rev1 rev2)))))
diff --git a/lisp/km-mail.el b/lisp/km-mail.el
index f021688..22d6b4e 100644
--- a/lisp/km-mail.el
+++ b/lisp/km-mail.el
@@ -183,7 +183,7 @@ in the remote's \".git/config\" entry."
(default-value 'notmuch-search-oldest-first)))
(declare-function debbugs-gnu-current-status "debbugs-gnu" ())
-;; Modified from fucntion in Nicolas Petton's emacs configuration
+;; Modified from function in Nicolas Petton's emacs configuration
;; (https://gitlab.petton.fr/nico/emacs.d/, 208407f53a)
;;;###autoload
(defun km/debbugs-notmuch-select-report (&rest _)
diff --git a/lisp/km-org-agenda.el b/lisp/km-org-agenda.el
index c0f9539..ded7afc 100644
--- a/lisp/km-org-agenda.el
+++ b/lisp/km-org-agenda.el
@@ -33,7 +33,7 @@
(defun km/org-agenda-cd-and-read-dir-locals ()
(unless (get 'org-agenda-files 'org-restrict)
- (setq default-directory (expand-file-name "~/notes/"))
+ (setq default-directory org-directory)
(hack-local-variables)))
(defun km/org-agenda-store-current-span ()
diff --git a/lisp/km-org.el b/lisp/km-org.el
index d4cc2f2..37ca829 100644
--- a/lisp/km-org.el
+++ b/lisp/km-org.el
@@ -537,6 +537,16 @@ beginning of the link."
(goto-char beg)
slurped))))
+;;;###autoload
+(defun km/org-copy-plain-file-link ()
+ (interactive)
+ (kill-new
+ (message
+ (concat "file:"
+ (abbreviate-file-name
+ (or (buffer-file-name)
+ (user-error "Buffer not visiting a file")))))))
+
;;; Export
diff --git a/lisp/km-python.el b/lisp/km-python.el
index 5f50131..339e8be 100644
--- a/lisp/km-python.el
+++ b/lisp/km-python.el
@@ -203,65 +203,5 @@ being turned on."
(when (< (current-indentation) indentation)
(indent-line-to indentation))))))
-
-;;; Pydoc
-
-(require 'pydoc)
-
-(defvar km/pydoc-names nil
- "List of names that have been sucessfully loaded by `pydoc'.")
-
-(defvar km/pydoc-names-file "~/.emacs.d/.pydoc-names"
- "File to save `km/pydoc-names' to.")
-
-;;;###autoload
-(defun km/pydoc ()
- "Run `pydoc', prompting with `km/pydoc-names'."
- (interactive)
- (let* ((default-directory "~/")
- (initial-name (and (use-region-p)
- (buffer-substring-no-properties
- (region-beginning)
- (region-end))))
- (name (completing-read "Name: " km/pydoc-names nil nil
- initial-name)))
- (pydoc name)))
-
-(defun km/pydoc-store-name ()
- "Store the name for the current pydoc object."
- (with-current-buffer (pydoc-buffer)
- (unless (eq (plist-get pydoc-info :type) 'not-found)
- (cl-pushnew (substring-no-properties (car (cdr help-xref-stack-item)))
- km/pydoc-names
- :test #'string=))))
-
-(defun km/pydoc-save-names-file (&optional file)
- "Save `km/pydoc-names' to FILE.
-FILE is `km/pydoc-names-file' by default."
- (interactive
- (list
- (read-file-name (format "Save file (default %s): "
- km/pydoc-names-file)
- nil km/pydoc-names-file t)))
- (setq file (or file km/pydoc-names-file))
- (when (file-writable-p file)
- (with-temp-file file
- (let (print-length)
- (print (sort km/pydoc-names #'string-lessp)
- (current-buffer))))))
-
-;;;###autoload
-(defun km/pydoc-read-names-file (&optional file)
- "Read `km/pydoc-names-file' from FILE.
-FILE is `km/pydoc-names-file' by default."
- (interactive
- (list
- (read-file-name (format "Read file (default %s): "
- km/pydoc-names-file)
- nil km/pydoc-names-file t)))
- (with-temp-buffer
- (insert-file-contents (or file km/pydoc-names-file))
- (setq km/pydoc-names (read (current-buffer)))))
-
(provide 'km-python)
;;; km-python.el ends here