Skip to content

Commit

Permalink
release: version 1.0.1
Browse files Browse the repository at this point in the history
- Use fringe-helper package to support fringe.
- Rename defcustom `org-linenote--highlight-style` to
`org-linenote-highlight-style`.
- Add some customizable variables:
  - org-linenote-use-highlight
  - org-linenote-use-fringe
  - org-linenote-fringe-side
  - org-linenote-fringe-bitmap
- Add a customizable face:
  - org-linenote-fringe-face

- Fixed a highlighting issue from the file-events occurred by
temporary files.
  • Loading branch information
seokbeomKim committed Dec 13, 2024
1 parent a816fb2 commit e21e0d5
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
- name: Run testcases
run: |
emacs --batch --eval "(progn (setq package-check-signature nil) (package-initialize) (add-to-list 'package-archives (cons \"melpa\" \"https://melpa.org/packages/\") t) (package-refresh-contents) (package-install 'projectile) (package-install 'vertico) (package-install 'lsp-mode))"
emacs --batch --eval "(progn (setq package-check-signature nil) (package-initialize) (add-to-list 'package-archives (cons \"melpa\" \"https://melpa.org/packages/\") t) (package-refresh-contents) (package-install 'projectile) (package-install 'vertico) (package-install 'lsp-mode) (package-install 'fringe-helper))"
emacs --batch --eval '(let ((default-directory "~/.emacs.d/elpa")) (normal-top-level-add-subdirs-to-load-path))' -l projectile -l org-linenote.el -l org-linenote-test.el -l ert -f ert-run-tests-batch-and-exit;
50 changes: 39 additions & 11 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ These features make =org-linenote= useful when you need 'line-by-line' notes to

* Usage

*How to create notes*
[[https://github.com/seokbeomKim/org-linenote/blob/image/example.gif]]

*Eldoc support*
https://github.com/seokbeomKim/org-linenote/blob/image/example-eldoc.png

** Interactive functions

The package provides interactive functions as follows:

- ~org-linenote-mode~: to enable Linenote's highlight on the current buffer.
Expand All @@ -41,6 +47,24 @@ The package provides interactive functions as follows:
- ~org-linenote-find-note-dir~: to find the note directory of the current buffer.
- ~org-linenote-auto-open~: to enable the note-following feature to view notes of the currently focused line.

** M-x customize

The following variables are customizable via ~M-x customize~.

- ~org-linenote-use-eldoc~: to enable or disable eldoc support.
- ~org-linenote-use-highlight~: to enable or disable line highlighting.
- ~org-linenote-use-fringe~: to enable or disable fringe support.
- ~org-linenote-fringe-side~: to configure the side of the fringes.

*** Fringe

- ~org-linenote-fringe-side~: to choose between ~'left-fringe~ or ~'right-fringe~.
- ~org-linenote-fringe-face~: to configure the face (i.e. color) of the fringes.
- ~org-linenote-fringe-bitmap~: to set the fringe bitmap style.

*** Highlight
- ~org-linenote-highlight-style~: to customize the style of highlighting.

** Single-line and multi-line notes

This package manages the notes by using relative paths and line numbers. Every note is stored in the =.linenote= directory in the project root directory with the relative path and the line number.
Expand All @@ -67,36 +91,40 @@ $ ln -sv $PROJECT/.linenote $PROJECT/.vscode/linenote

* Change-Log

** 1.0.1
- Added support for fringes.
- Fixed a highlighting issue caused by temporary files.

** 1.0.0
- Add eldoc support.
- Fix a bug on revert-buffer.
- Added eldoc support.
- Fixed a bug on revert-buffer.

** 0.2.2
- Change =org-linenote--default-extension= and =org-linenote--highlight-style= to customizable variables. Now it is available in =M-x customize=.
- Changed =org-linenote--default-extension= and =org-linenote--highlight-style= to customizable variables. Now it is available in =M-x customize=.

** 0.2.1
- Add an interactive function to toggle auto-open feature
- Added an interactive function to toggle auto-open feature
- Fixed incorrect function names

** 0.2.0
- Fix a bug on mode activation
- Add a feature to auto highlight by filenotify events
- Add interactive functions to move to the next/previous note
- Add interactive functions to find Linenote directory
- Fixed a bug on mode activation
- Added a feature to auto highlight by filenotify events
- Added interactive functions to move to the next/previous note
- Added interactive functions to find Linenote directory

** 0.1.2
- Refactor org-linenote-mode to use minor-mode
- Refactored org-linenote-mode to use minor-mode
- Modified code according to MELPA PR feedbacks (https://github.com/melpa/melpa/pull/8955)

** 0.1.1
- Fix a bug on note browsing
- Fixed a bug on note browsing
- Add =org-linenote--default-extension=

** 0.1.0
- initial version

* To-Do
- eldoc support
- tag support

* Feedback

Expand Down
110 changes: 89 additions & 21 deletions org-linenote.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
;; Maintainer: Jason Kim <sukbeom.kim@gmail.com>
;; Created: February 18, 2024
;; Modified: April 10, 2024
;; Version: 1.0.0
;; Version: 1.0.1
;; Keywords: tools, note, org
;; Homepage: https://github.com/seokbeomKim/org-linenote
;; Package-Requires: ((emacs "29.1") (projectile "2.8.0") (vertico "1.7") (eldoc "1.11") (lsp-mode "9.0.0"))
;; Package-Requires: ((emacs "29.1") (projectile "2.8.0") (vertico "1.7") (eldoc "1.11") (lsp-mode "9.0.0") (fringe-helper "1.0.1"))

;; This file is not part of GNU Emacs.

Expand Down Expand Up @@ -55,6 +55,7 @@
(require 'filenotify)
(require 'lsp-mode)
(require 'eldoc)
(require 'fringe-helper)

(defcustom org-linenote-default-extension ".org"
"Configure the default note extension.
Expand All @@ -70,8 +71,31 @@ to disable eldoc."
:type 'boolean
:group 'org-linenote)

(defface org-linenote--highlight-style '((t :background "medium turquoise" :underline nil))
"Highlight style for the note.")
(defcustom org-linenote-use-highlight t
"Enable highlighting for notes.
If non-nil, the line with the note will be highlighted. Set to nil not
to disable this feature."
:type 'boolean
:group 'org-linenote)

(defcustom org-linenote-use-fringe t
"Enable the fringe to display the notes.
If non-nil, a fringe bitmap indicating notes will appear in the buffer.
Set to nil to disable the fringe."
:type 'boolean
:group 'org-linenote)

(defcustom org-linenote-fringe-side 'left-fringe
"Set the fringe position.
Either \='left-fringe or \='right-fringe is available."
:type 'symbol
:group 'org-linenote)

(defface org-linenote-highlight-style '((t :background "medium turquoise" :underline nil))
"Highlight style for the notes.")

(defface org-linenote-fringe-face '((t :foreground "#aaaaee" :weight bold))
"Fringe color for the notes.")

(defvar org-linenote--in-browse nil
"A flag of browse function.")
Expand All @@ -82,6 +106,20 @@ to disable eldoc."
(defvar org-linenote--buffers nil
"The target buffer to ensure line tracking.")

(eval-and-compile
(defcustom org-linenote-fringe-bitmap
'("XX......"
"XX......"
"XX..XX.."
"XX..XX.."
"XX..XX.."
"XX..XX.."
"XX......"
"XX......")
"Define a fringe bitmap to indicate notes."
:type '(repeat string)
:group 'org-linenote))

(defvar-local org-linenote--overlays nil
"Overlays in a local buffer.")

Expand All @@ -95,6 +133,9 @@ the cursor.")
(defvar-local org-linenote-mode nil
"Org-linenote mode flag.")

(defvar-local org-linenote--fringes nil
"A list of fringes.")

(defun org-linenote--lines-to-highlight (filename)
"Get beginning/end line number to highlight from `FILENAME'."
(let* ((basename filename)
Expand All @@ -115,19 +156,35 @@ if `UNDO' is t, then unhighlight regions related to `FILENAME'."
(diff-line (- max-line min-line)))
(goto-char (point-min))
(forward-line min-line)
(beginning-of-line)
(set-mark (line-beginning-position))
(forward-line diff-line)
(org-linenote--remove-overlays-at (region-beginning))
(if (null undo)
(let ((ov (make-overlay (region-beginning) (- (region-end) 1))))
(overlay-put ov 'face 'org-linenote--highlight-style)
(if (overlay-buffer ov)
(push ov org-linenote--overlays))))
(forward-line -1)
(deactivate-mark)
(goto-char (point-min))
(forward-line min-line)))

(mapcar (lambda (v) (delete-overlay v))
(overlays-in (line-beginning-position) (line-end-position)))

(when org-linenote-use-fringe
(fringe-helper-define 'org-linenote--fringe-bitmap '(center)
(mapconcat #'identity org-linenote-fringe-bitmap "\n"))

(if (null undo)
(push (fringe-helper-insert 'org-linenote--fringe-bitmap
(point)
org-linenote-fringe-side
'org-linenote-fringe-face)
org-linenote--fringes)))

(when org-linenote-use-highlight
(beginning-of-line)
(set-mark (line-beginning-position))
(forward-line diff-line)
(org-linenote--remove-overlays-at (region-beginning))
(if (null undo)
(let ((ov (make-overlay (region-beginning) (- (region-end) 1))))
(overlay-put ov 'face 'org-linenote-highlight-style)
(if (overlay-buffer ov)
(push ov org-linenote--overlays))))
(forward-line -1)
(deactivate-mark)
(goto-char (point-min))
(forward-line min-line))))

(defun org-linenote-mark-notes ()
"Highlight lines with annotated notes."
Expand Down Expand Up @@ -355,17 +412,22 @@ change the focus after the line highlight."
(org-linenote--remove-overlays-at (line-beginning-position))
(remove-hook 'post-command-hook #'org-linenote--post-command-hook))

(defun org-linenote--is-backup-file (file-path)
"Check the file located at `FILE-PATH is temporary file."
(string= (substring (file-name-base file-path) 0 2) ".#"))

(defun org-linenote--file-changed (event)
"A function to handle file watch `EVENT'."
(let* ((fs-id (nth 0 event))
(etype (nth 1 event))
(fpath (nth 2 event))
(buffer-of-event (cdr (assoc fs-id org-linenote--buffers))))

(when (string-match-p
(regexp-quote (file-name-nondirectory
(buffer-file-name buffer-of-event)))
(file-name-base fpath))
(when (and (string-match-p
(regexp-quote (file-name-nondirectory
(buffer-file-name buffer-of-event)))
(file-name-base fpath))
(not (org-linenote--is-backup-file fpath)))
(with-current-buffer buffer-of-event
(cond
((string= etype "deleted")
Expand All @@ -388,6 +450,10 @@ change the focus after the line highlight."
"Remove all overlays in the current buffer."
(mapc #'delete-overlay org-linenote--overlays))

(defun org-linenote--remove-all-fringes ()
"Remove all fringes in the current buffer."
(mapc #'fringe-helper-remove org-linenote--fringes))

(defun org-linenote--enable ()
"A function to enable `org-linenote-mode'."
(org-linenote--validate)
Expand All @@ -396,6 +462,7 @@ change the focus after the line highlight."
(add-hook 'minibuffer-exit-hook #'org-linenote--minibuf-exit-hook)
(add-hook 'kill-buffer-hook #'org-linenote--buffer-killed :local)
(add-hook 'before-revert-hook #'org-linenote--remove-all-overlays :local)
(add-hook 'before-revert-hook #'org-linenote--remove-all-fringes :local)

(let* ((watch-directory (expand-file-name (or (file-name-directory (org-linenote--get-relpath)) "")
(org-linenote--get-note-rootdir)))
Expand Down Expand Up @@ -423,6 +490,7 @@ change the focus after the line highlight."
(remove-hook 'before-revert-hook #'org-linenote--remove-all-overlays :local)

(org-linenote--remove-all-overlays)
(org-linenote--remove-all-fringes)
(org-linenote--auto-open-at-cursor 'false)
(org-linenote--dealloc-fswatch))

Expand Down

0 comments on commit e21e0d5

Please sign in to comment.