From 5af9e1543be44d2615171409d8647b20656647dc Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Tue, 27 Jul 2021 15:25:51 +0100 Subject: [PATCH] Add the bookmark cube --- config/fg42.user.v3.el | 2 + core/cubes/bookmark.el | 99 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 core/cubes/bookmark.el diff --git a/config/fg42.user.v3.el b/config/fg42.user.v3.el index a631caa..047ebe1 100644 --- a/config/fg42.user.v3.el +++ b/config/fg42.user.v3.el @@ -38,6 +38,7 @@ (require 'cubes/snippets) (require 'cubes/org) (require 'cubes/git) +(require 'cubes/bookmark) ;; ============== MY STUFF ============================== (custom-set-faces @@ -129,6 +130,7 @@ (fg42/vterm-cube) (fg42/git-cube) +(fg42/bookmark-cube) (fg42/java-cube) (fg42/yasnippet-cube) ;; Themes should be the last cube and anything that wants to manipulate a face diff --git a/core/cubes/bookmark.el b/core/cubes/bookmark.el new file mode 100644 index 0000000..6225205 --- /dev/null +++ b/core/cubes/bookmark.el @@ -0,0 +1,99 @@ +;;; Bookmark --- Bookmarks within the code -*- lexical-binding: t; -*- +;; +;; Copyright (c) 2010-2021 Sameer Rahmani & Contributors +;; +;; Author: Sameer Rahmani +;; URL: https://gitlab.com/FG42/FG42 +;; Version: 3.0.0 +;; +;; 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 thnis program. If not, see . +;; +;;; Commentary: +;; Cubes are the building blocks of any `FG42' editor. Each `cube' is a +;; unit which defines different abilities in a deterministic and idempotent +;; way. Cubes are composable and a composition of cubes creates an editor. +;; +;;; Code: +(require 'fpkg) +(require 'fg42/cube) + + +(defcube fg42/bookmark-cube + (:docs "cubes/fg42/bookmark-cube.org" + :flag bookmark + :flag-default t) + + (let* ((bnext (or (plist-get fg42/bookmark-cube-params :bm-next-key) "M-]")) + (bprev (or (plist-get fg42/bookmark-cube-params :bm-previous-key) "M-[")) + (btoggle (or (plist-get fg42/bookmark-cube-params :bm-toggel-key) "M-p")) + (keys `(list (,bnext . bm-next) + (,bprev . bm-previous) + (,btoggle . bm-toggle)))) + (eval + `(fpkg/use bm + :init + ;; restore on load (even before you require bm) + (setq bm-restore-repository-on-load t) + + + + :config + ;; Allow cross-buffer 'next' + (setq bm-cycle-all-buffers t) + + ;; where to store persistant files + (setq bm-repository-file (expand-file-name "bm-repository" user-emacs-directory)) + + ;; save bookmarks + (setq-default bm-buffer-persistence t) + + ;; Loading the repository from file when on start up. + (add-hook 'after-init-hook 'bm-repository-load) + + ;; Saving bookmarks + (add-hook 'kill-buffer-hook #'bm-buffer-save) + + ;; Saving the repository to file when on exit. + ;; kill-buffer-hook is not called when Emacs is killed, so we + ;; must save all bookmarks first. + (add-hook 'kill-emacs-hook #'(lambda nil + (bm-buffer-save-all) + (bm-repository-save))) + + ;; The `after-save-hook' is not necessary to use to achieve persistence, + ;; but it makes the bookmark data in repository more in sync with the file + ;; state. + (add-hook 'after-save-hook #'bm-buffer-save) + + ;; Restoring bookmarks + (add-hook 'find-file-hooks #'bm-buffer-restore) + (add-hook 'after-revert-hook #'bm-buffer-restore) + + ;; The `after-revert-hook' is not necessary to use to achieve persistence, + ;; but it makes the bookmark data in repository more in sync with the file + ;; state. This hook might cause trouble when using packages + ;; that automatically reverts the buffer (like vc after a check-in). + ;; This can easily be avoided if the package provides a hook that is + ;; called before the buffer is reverted (like `vc-before-checkin-hook'). + ;; Then new bookmarks can be saved before the buffer is reverted. + ;; Make sure bookmarks is saved before check-in (and revert-buffer) + (add-hook 'vc-before-checkin-hook #'bm-buffer-save) + + + :bind ((,bnext . bm-next) + (,bprev . bm-previous) + (,btoggle . bm-toggle)))))) + +(provide 'cubes/bookmark) +;;; bookmark.el ends here