emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Read only org view mode
@ 2022-01-23  7:19 Arthur Miller
  2022-01-24  6:20 ` Marcin Borkowski
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Arthur Miller @ 2022-01-23  7:19 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 682 bytes --]

Hi mailing list,

is something like this of interest to add to org-mode?

Attached is a prototype to a read-only view mode. It tries to hide as much of
markup as possible to make it more "readable". It uses built-in view-mode to
make the buffer read only and enable some common commands. I plan to add more
"dired like" movement though.

I don't claim it is very well written or efficient; I appreciate input on that
regard. To note is that I use minor-modes as "toggles", to make the
functionality avialable as "solo pieces" as well as a code generation tool.

I am just checking interest here. More info and a screencast are avialable at:

https://github.com/amno1/org-view-mode


[-- Attachment #2: org-view-mode.el --]
[-- Type: text/plain, Size: 8140 bytes --]

;;; org-view-mode.el --- Read-only viewer with less markup clutter in org mode files  -*- lexical-binding: t; -*-

;; Copyright (C) 2021  Arthur Miller

;; Author: Arthur Miller <arthur.miller@live.com>
;; Keywords: convenience, outlines, tools

;; 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 <https://www.gnu.org/licenses/>.

;; Author: Arthur Miller
;; Version: 0.0.1
;; Keywords: tools convenience
;; Package-Requires: ((emacs "24.1"))
;; URL: https://github.com/amno1/org-view-mode

;;; Commentary:

;; A minor mode to help reduce clutter in org-mode files by
;; hiding/unhiding org-mode markup language
;;
;; To turn it on execute:
;;
;;          `M-x org-view-mode'.
;;
;; To turn it off execute the same command.

;;; Issues

;;; Code:
(require 'org)

(defgroup org-view nil
  "Hide tags in org-headings."
  :prefix "org-view-"
  :group 'org)

(defvar-local org-view-center-credentials nil
  "Whether to align title and author in center or not.

Centering is done pixel wise relative to window width.")

(defcustom org-view-diminish-mode t
  "Hide lighters for individual minor modes when org-view-mode is on."
  :type 'boolean
  :group 'org-view)

(defvar org-view-stars-re "^[ \t]*\\*+"
  "Regex used to recognize leading stars in org-headings.")

(defvar org-view-credentials-re "[ \t]*#\\+\\(TITLE\\|AUTHOR\\):"
  "Regex used to update author and title lines.")

(defun org-view--update-tags (visibility)
  "Update invisible property to VISIBILITY for tags in the current buffer."
  (save-excursion
    (goto-char (point-min))
    (with-silent-modifications
      (while (re-search-forward org-view-stars-re nil t)
        (goto-char (line-end-position))
        (when (re-search-backward org-tag-line-re (line-beginning-position) t)
            (put-text-property
             (match-beginning 1) (match-end 1) 'invisible visibility))
          (forward-line)))))

(defun org-view--update-keywords (visibility)
  "Set VISIBILITY for each line starting with a keyword from KEYWORDS list."
  (org-with-wide-buffer
   (save-excursion
     (with-silent-modifications
       (goto-char (point-min))
       (while (re-search-forward "^[ \t]*#\\+.*$" nil t)
         (goto-char (match-beginning 0))
         (unless (looking-at-p org-view-credentials-re)
           (put-text-property
            (1- (match-beginning 0)) (match-end 0) 'invisible visibility))
         (goto-char (match-end 0)))))))

(defun org-view--update-properties (visibility)
  "Set invisible property to VISIBILITY for properties in the current buffer."
  (org-with-wide-buffer
   (save-excursion
     (with-silent-modifications
       (goto-char (point-min))
       (while (re-search-forward org-property-drawer-re nil t)
         (put-text-property
          (match-beginning 0) (match-end 0) 'invisible visibility))
       (goto-char (point-min))
       (while (re-search-forward "^[ \t]*#\\+PROPERTY:.*$" nil t)
         (put-text-property
          (1- (match-beginning 0)) (1+ (match-end 0)) 'invisible visibility))))))

(defun org-view--update-stars (visibility)
  "Update invisible property to VISIBILITY for markers in the current buffer."
  (org-with-wide-buffer
   (save-excursion
     (goto-char (point-min))
     (with-silent-modifications
       (while (re-search-forward org-view-stars-re nil t)
         (put-text-property
          (match-beginning 0) (match-end 0) 'invisible visibility))))))

(defun org-view--update-credentials (visibility)
  "Set invisible property to VISIBILITY for export settings."
  (org-with-wide-buffer
   (save-excursion
     (with-silent-modifications
       (goto-char (point-min))         
       (while (re-search-forward org-view-credentials-re nil t)
         (put-text-property
          (match-beginning 0) (match-end 0) 'invisible visibility)
         (when org-view-center-credentials
           (org-view--center-in-window visibility)))
       (goto-char (point-min))))))

(defun org-view--center-in-window (center)
  "Center a line in a window pixel wise."
  (save-excursion
    (goto-char (line-beginning-position))
    (let ((end (line-end-position))
          (beg (line-beginning-position)))
      (if center
          (let* ((line (buffer-substring beg end))
                 (length (/ (string-pixel-width line) 2)))
            (put-text-property
             beg (1+ beg) 'display `(space :align-to (- center (,length)))))
        (remove-text-properties beg (1+ beg) '(display nil))))))

;;;###autoload
(define-minor-mode org-view-hide-tags-mode
  "Hide/show tags in org-headings."
  :global nil :lighter " org-htm"
  (unless (derived-mode-p 'org-mode)
    (error "Not in org-mode"))
  (org-view--update-tags org-view-hide-tags-mode))

;;;###autoload
(define-minor-mode org-view-hide-stars-mode
  "Hide/show leading stars in org-headings."
  :global nil :lighter " org-hsm"
  (unless (derived-mode-p 'org-mode)
    (error "Not in org-mode"))
  (org-view--update-stars org-view-hide-stars-mode))

;;;###autoload
(define-minor-mode org-view-hide-keywords-mode
  "Hide/show leading stars in org-headings."
  :global nil :lighter " org-hkm"
  (unless (derived-mode-p 'org-mode)
    (error "Not in org-mode"))
  (org-view--update-keywords org-view-hide-stars-mode))

;;;###autoload
(define-minor-mode org-view-hide-properties-mode
  "Hide/show properties and property drawers."
  :global nil :lighter " org-hpm"
  (unless (derived-mode-p 'org-mode)
    (error "Not in org-mode"))
  (org-view--update-properties org-view-hide-properties-mode))

;;;###autoload
(define-minor-mode org-view-pretty-credentials-mode
  "Prettify credentials in org-buffers."
  :global nil :lighter " org-pcm"
  (unless (derived-mode-p 'org-mode)
    (error "Not in org-mode"))
  (org-view--update-credentials org-view-pretty-credentials-mode))

(defun org-view-quit ()
  (interactive)
  (org-view-mode -1)
  (message "org-view mode disabled in current buffer"))

(defvar-keymap org-view-mode-map
  :doc "Keymap for ‘ORG-view-mode’"
  "c" #'org-view-quit
  "C" #'org-view-quit
  "e" #'org-view-quit
  "E" #'org-view-quit
  "q" #'org-view-quit
  "Q" #'org-view-quit)

;;;###autoload
(define-minor-mode org-view-mode
  "Hide/show babel source code blocks on demand."
  :global nil :lighter " org-view" :keymap org-view-mode-map
  (unless (derived-mode-p 'org-mode)
    (error "Not in org-mode"))
  (cond (org-view-mode
         (org-view-hide-tags-mode org-view-mode)
         (org-view-hide-stars-mode org-view-mode)
         (org-view-hide-keywords-mode org-view-mode)
         (org-view-hide-properties-mode org-view-mode)
         (org-view-pretty-credentials-mode org-view-mode)
         (when org-view-diminish-mode
           (dolist (mode '(org-view-hide-tags-mode
                           org-view-hide-stars-mode
                           org-view-hide-keywords-mode
                           org-view-hide-properties-mode
                           org-view-pretty-credentials-mode))
             (let ((mode-str (cdr (assq mode minor-mode-alist))))
               (setcar mode-str ""))))
         (view-mode +1))
        (t (view-mode -1)
           (org-view-hide-tags-mode -1)
           (org-view-hide-stars-mode -1)
           (org-view-hide-keywords-mode -1)
           (org-view-hide-properties-mode -1)
           (org-view-pretty-credentials-mode -1))))

(provide 'org-view-mode)

;;; org-view-mode.el ends here

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Read only org view mode
  2022-01-23  7:19 Read only org view mode Arthur Miller
@ 2022-01-24  6:20 ` Marcin Borkowski
  2022-01-24 10:30 ` Neil Jerram
  2022-01-24 11:11 ` Russell Adams
  2 siblings, 0 replies; 6+ messages in thread
From: Marcin Borkowski @ 2022-01-24  6:20 UTC (permalink / raw)
  To: Arthur Miller; +Cc: emacs-orgmode


On 2022-01-23, at 08:19, Arthur Miller <arthur.miller@live.com> wrote:

> Hi mailing list,
>
> is something like this of interest to add to org-mode?

Yes! Yes! Yes!

I can see all sorts of stuff going from here.  Three examples follow.

1. I have a daily journal in Org-mode, and I wrote a simple function
showing me "what happened on this day in all previous years of
journaling".  Making that read-only, with view-mode-like bindings is an
obvious thing to do.  (In fact, I plan to blog about that function
soon.)

2. I imagine this could be used to create menus, a bit like Magit, with
toggleable sections etc.

3. I once coded myself a kind of "dashboard", showing various things in
(almost) real time - think current time, weather, departures of busses
from a nearby bus stop, Emacs uptime, number of open buffers, a todo
list for today etc.  (Sadly, I didn't finish it, though.)  A mode
derived from your mode could be great for that.

Thanks a lot for working on this,

-- 
Marcin Borkowski
http://mbork.pl


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Read only org view mode
  2022-01-23  7:19 Read only org view mode Arthur Miller
  2022-01-24  6:20 ` Marcin Borkowski
@ 2022-01-24 10:30 ` Neil Jerram
  2022-01-24 11:11 ` Russell Adams
  2 siblings, 0 replies; 6+ messages in thread
From: Neil Jerram @ 2022-01-24 10:30 UTC (permalink / raw)
  To: Arthur Miller; +Cc: emacs-orgmode

Hi Arthur,

On Sun, 23 Jan 2022 at 07:53, Arthur Miller <arthur.miller@live.com> wrote:
>
> Hi mailing list,
>
> is something like this of interest to add to org-mode?

I'm interested in Linux-native smartphones (e.g. the Pine Phone) and
in using Org there as fully as possible.  I probably wouldn't _alter_
my Org content on the phone as extensively as I do on a laptop, but
I'd certainly like to _see_ all my Org content and have something like
an agenda.  Then the question arises of how best to display that
content and support occasional editing of it.  Apps like Orgzly have
been developed to meet this need, but (a) Orgzly is Android-specific,
and (b) I would really love if a good answer could be: simply run
Emacs on the phone and view your Org content that way.  A read-only
Org view mode feels like it could be a very useful ingredient for
that!

Best wishes,
   Neil


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Read only org view mode
  2022-01-23  7:19 Read only org view mode Arthur Miller
  2022-01-24  6:20 ` Marcin Borkowski
  2022-01-24 10:30 ` Neil Jerram
@ 2022-01-24 11:11 ` Russell Adams
  2022-01-24 11:40   ` Neil Jerram
  2 siblings, 1 reply; 6+ messages in thread
From: Russell Adams @ 2022-01-24 11:11 UTC (permalink / raw)
  To: emacs-orgmode

Why not just do an ASCII export to a temporary read only buffer for
viewing?

I always thought the point of Org was to have minimal markup so that
the native file was plainly legible.

On Sun, Jan 23, 2022 at 08:19:12AM +0100, Arthur Miller wrote:
> Hi mailing list,
>
> is something like this of interest to add to org-mode?
>
> Attached is a prototype to a read-only view mode. It tries to hide as much of
> markup as possible to make it more "readable". It uses built-in view-mode to
> make the buffer read only and enable some common commands. I plan to add more
> "dired like" movement though.
>
> I don't claim it is very well written or efficient; I appreciate input on that
> regard. To note is that I use minor-modes as "toggles", to make the
> functionality avialable as "solo pieces" as well as a code generation tool.
>
> I am just checking interest here. More info and a screencast are avialable at:
>
> https://github.com/amno1/org-view-mode
>

> ;;; org-view-mode.el --- Read-only viewer with less markup clutter in org mode files  -*- lexical-binding: t; -*-
>
> ;; Copyright (C) 2021  Arthur Miller
>
> ;; Author: Arthur Miller <arthur.miller@live.com>
> ;; Keywords: convenience, outlines, tools
>
> ;; 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 <https://www.gnu.org/licenses/>.
>
> ;; Author: Arthur Miller
> ;; Version: 0.0.1
> ;; Keywords: tools convenience
> ;; Package-Requires: ((emacs "24.1"))
> ;; URL: https://github.com/amno1/org-view-mode
>
> ;;; Commentary:
>
> ;; A minor mode to help reduce clutter in org-mode files by
> ;; hiding/unhiding org-mode markup language
> ;;
> ;; To turn it on execute:
> ;;
> ;;          `M-x org-view-mode'.
> ;;
> ;; To turn it off execute the same command.
>
> ;;; Issues
>
> ;;; Code:
> (require 'org)
>
> (defgroup org-view nil
>   "Hide tags in org-headings."
>   :prefix "org-view-"
>   :group 'org)
>
> (defvar-local org-view-center-credentials nil
>   "Whether to align title and author in center or not.
>
> Centering is done pixel wise relative to window width.")
>
> (defcustom org-view-diminish-mode t
>   "Hide lighters for individual minor modes when org-view-mode is on."
>   :type 'boolean
>   :group 'org-view)
>
> (defvar org-view-stars-re "^[ \t]*\\*+"
>   "Regex used to recognize leading stars in org-headings.")
>
> (defvar org-view-credentials-re "[ \t]*#\\+\\(TITLE\\|AUTHOR\\):"
>   "Regex used to update author and title lines.")
>
> (defun org-view--update-tags (visibility)
>   "Update invisible property to VISIBILITY for tags in the current buffer."
>   (save-excursion
>     (goto-char (point-min))
>     (with-silent-modifications
>       (while (re-search-forward org-view-stars-re nil t)
>         (goto-char (line-end-position))
>         (when (re-search-backward org-tag-line-re (line-beginning-position) t)
>             (put-text-property
>              (match-beginning 1) (match-end 1) 'invisible visibility))
>           (forward-line)))))
>
> (defun org-view--update-keywords (visibility)
>   "Set VISIBILITY for each line starting with a keyword from KEYWORDS list."
>   (org-with-wide-buffer
>    (save-excursion
>      (with-silent-modifications
>        (goto-char (point-min))
>        (while (re-search-forward "^[ \t]*#\\+.*$" nil t)
>          (goto-char (match-beginning 0))
>          (unless (looking-at-p org-view-credentials-re)
>            (put-text-property
>             (1- (match-beginning 0)) (match-end 0) 'invisible visibility))
>          (goto-char (match-end 0)))))))
>
> (defun org-view--update-properties (visibility)
>   "Set invisible property to VISIBILITY for properties in the current buffer."
>   (org-with-wide-buffer
>    (save-excursion
>      (with-silent-modifications
>        (goto-char (point-min))
>        (while (re-search-forward org-property-drawer-re nil t)
>          (put-text-property
>           (match-beginning 0) (match-end 0) 'invisible visibility))
>        (goto-char (point-min))
>        (while (re-search-forward "^[ \t]*#\\+PROPERTY:.*$" nil t)
>          (put-text-property
>           (1- (match-beginning 0)) (1+ (match-end 0)) 'invisible visibility))))))
>
> (defun org-view--update-stars (visibility)
>   "Update invisible property to VISIBILITY for markers in the current buffer."
>   (org-with-wide-buffer
>    (save-excursion
>      (goto-char (point-min))
>      (with-silent-modifications
>        (while (re-search-forward org-view-stars-re nil t)
>          (put-text-property
>           (match-beginning 0) (match-end 0) 'invisible visibility))))))
>
> (defun org-view--update-credentials (visibility)
>   "Set invisible property to VISIBILITY for export settings."
>   (org-with-wide-buffer
>    (save-excursion
>      (with-silent-modifications
>        (goto-char (point-min))
>        (while (re-search-forward org-view-credentials-re nil t)
>          (put-text-property
>           (match-beginning 0) (match-end 0) 'invisible visibility)
>          (when org-view-center-credentials
>            (org-view--center-in-window visibility)))
>        (goto-char (point-min))))))
>
> (defun org-view--center-in-window (center)
>   "Center a line in a window pixel wise."
>   (save-excursion
>     (goto-char (line-beginning-position))
>     (let ((end (line-end-position))
>           (beg (line-beginning-position)))
>       (if center
>           (let* ((line (buffer-substring beg end))
>                  (length (/ (string-pixel-width line) 2)))
>             (put-text-property
>              beg (1+ beg) 'display `(space :align-to (- center (,length)))))
>         (remove-text-properties beg (1+ beg) '(display nil))))))
>
> ;;;###autoload
> (define-minor-mode org-view-hide-tags-mode
>   "Hide/show tags in org-headings."
>   :global nil :lighter " org-htm"
>   (unless (derived-mode-p 'org-mode)
>     (error "Not in org-mode"))
>   (org-view--update-tags org-view-hide-tags-mode))
>
> ;;;###autoload
> (define-minor-mode org-view-hide-stars-mode
>   "Hide/show leading stars in org-headings."
>   :global nil :lighter " org-hsm"
>   (unless (derived-mode-p 'org-mode)
>     (error "Not in org-mode"))
>   (org-view--update-stars org-view-hide-stars-mode))
>
> ;;;###autoload
> (define-minor-mode org-view-hide-keywords-mode
>   "Hide/show leading stars in org-headings."
>   :global nil :lighter " org-hkm"
>   (unless (derived-mode-p 'org-mode)
>     (error "Not in org-mode"))
>   (org-view--update-keywords org-view-hide-stars-mode))
>
> ;;;###autoload
> (define-minor-mode org-view-hide-properties-mode
>   "Hide/show properties and property drawers."
>   :global nil :lighter " org-hpm"
>   (unless (derived-mode-p 'org-mode)
>     (error "Not in org-mode"))
>   (org-view--update-properties org-view-hide-properties-mode))
>
> ;;;###autoload
> (define-minor-mode org-view-pretty-credentials-mode
>   "Prettify credentials in org-buffers."
>   :global nil :lighter " org-pcm"
>   (unless (derived-mode-p 'org-mode)
>     (error "Not in org-mode"))
>   (org-view--update-credentials org-view-pretty-credentials-mode))
>
> (defun org-view-quit ()
>   (interactive)
>   (org-view-mode -1)
>   (message "org-view mode disabled in current buffer"))
>
> (defvar-keymap org-view-mode-map
>   :doc "Keymap for ‘ORG-view-mode’"
>   "c" #'org-view-quit
>   "C" #'org-view-quit
>   "e" #'org-view-quit
>   "E" #'org-view-quit
>   "q" #'org-view-quit
>   "Q" #'org-view-quit)
>
> ;;;###autoload
> (define-minor-mode org-view-mode
>   "Hide/show babel source code blocks on demand."
>   :global nil :lighter " org-view" :keymap org-view-mode-map
>   (unless (derived-mode-p 'org-mode)
>     (error "Not in org-mode"))
>   (cond (org-view-mode
>          (org-view-hide-tags-mode org-view-mode)
>          (org-view-hide-stars-mode org-view-mode)
>          (org-view-hide-keywords-mode org-view-mode)
>          (org-view-hide-properties-mode org-view-mode)
>          (org-view-pretty-credentials-mode org-view-mode)
>          (when org-view-diminish-mode
>            (dolist (mode '(org-view-hide-tags-mode
>                            org-view-hide-stars-mode
>                            org-view-hide-keywords-mode
>                            org-view-hide-properties-mode
>                            org-view-pretty-credentials-mode))
>              (let ((mode-str (cdr (assq mode minor-mode-alist))))
>                (setcar mode-str ""))))
>          (view-mode +1))
>         (t (view-mode -1)
>            (org-view-hide-tags-mode -1)
>            (org-view-hide-stars-mode -1)
>            (org-view-hide-keywords-mode -1)
>            (org-view-hide-properties-mode -1)
>            (org-view-pretty-credentials-mode -1))))
>
> (provide 'org-view-mode)
>
> ;;; org-view-mode.el ends here



------------------------------------------------------------------
Russell Adams                            RLAdams@AdamsInfoServ.com

PGP Key ID:     0x1160DCB3           http://www.adamsinfoserv.com/

Fingerprint:    1723 D8CA 4280 1EC9 557F  66E8 1154 E018 1160 DCB3


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Read only org view mode
  2022-01-24 11:11 ` Russell Adams
@ 2022-01-24 11:40   ` Neil Jerram
  2022-01-24 12:58     ` Russell Adams
  0 siblings, 1 reply; 6+ messages in thread
From: Neil Jerram @ 2022-01-24 11:40 UTC (permalink / raw)
  To: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 10569 bytes --]

On Mon, 24 Jan 2022, 11:14 Russell Adams, <RLAdams@adamsinfoserv.com> wrote:

> Why not just do an ASCII export to a temporary read only buffer for
> viewing?
>

Do you mean that you're agreeing with the concept, but finding the
implementation unnecessarily complicated?


> I always thought the point of Org was to have minimal markup so that
> the native file was plainly legible.
>
> On Sun, Jan 23, 2022 at 08:19:12AM +0100, Arthur Miller wrote:
> > Hi mailing list,
> >
> > is something like this of interest to add to org-mode?
> >
> > Attached is a prototype to a read-only view mode. It tries to hide as
> much of
> > markup as possible to make it more "readable". It uses built-in
> view-mode to
> > make the buffer read only and enable some common commands. I plan to add
> more
> > "dired like" movement though.
> >
> > I don't claim it is very well written or efficient; I appreciate input
> on that
> > regard. To note is that I use minor-modes as "toggles", to make the
> > functionality avialable as "solo pieces" as well as a code generation
> tool.
> >
> > I am just checking interest here. More info and a screencast are
> avialable at:
> >
> > https://github.com/amno1/org-view-mode
> >
>
> > ;;; org-view-mode.el --- Read-only viewer with less markup clutter in
> org mode files  -*- lexical-binding: t; -*-
> >
> > ;; Copyright (C) 2021  Arthur Miller
> >
> > ;; Author: Arthur Miller <arthur.miller@live.com>
> > ;; Keywords: convenience, outlines, tools
> >
> > ;; 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 <https://www.gnu.org/licenses/
> >.
> >
> > ;; Author: Arthur Miller
> > ;; Version: 0.0.1
> > ;; Keywords: tools convenience
> > ;; Package-Requires: ((emacs "24.1"))
> > ;; URL: https://github.com/amno1/org-view-mode
> >
> > ;;; Commentary:
> >
> > ;; A minor mode to help reduce clutter in org-mode files by
> > ;; hiding/unhiding org-mode markup language
> > ;;
> > ;; To turn it on execute:
> > ;;
> > ;;          `M-x org-view-mode'.
> > ;;
> > ;; To turn it off execute the same command.
> >
> > ;;; Issues
> >
> > ;;; Code:
> > (require 'org)
> >
> > (defgroup org-view nil
> >   "Hide tags in org-headings."
> >   :prefix "org-view-"
> >   :group 'org)
> >
> > (defvar-local org-view-center-credentials nil
> >   "Whether to align title and author in center or not.
> >
> > Centering is done pixel wise relative to window width.")
> >
> > (defcustom org-view-diminish-mode t
> >   "Hide lighters for individual minor modes when org-view-mode is on."
> >   :type 'boolean
> >   :group 'org-view)
> >
> > (defvar org-view-stars-re "^[ \t]*\\*+"
> >   "Regex used to recognize leading stars in org-headings.")
> >
> > (defvar org-view-credentials-re "[ \t]*#\\+\\(TITLE\\|AUTHOR\\):"
> >   "Regex used to update author and title lines.")
> >
> > (defun org-view--update-tags (visibility)
> >   "Update invisible property to VISIBILITY for tags in the current
> buffer."
> >   (save-excursion
> >     (goto-char (point-min))
> >     (with-silent-modifications
> >       (while (re-search-forward org-view-stars-re nil t)
> >         (goto-char (line-end-position))
> >         (when (re-search-backward org-tag-line-re
> (line-beginning-position) t)
> >             (put-text-property
> >              (match-beginning 1) (match-end 1) 'invisible visibility))
> >           (forward-line)))))
> >
> > (defun org-view--update-keywords (visibility)
> >   "Set VISIBILITY for each line starting with a keyword from KEYWORDS
> list."
> >   (org-with-wide-buffer
> >    (save-excursion
> >      (with-silent-modifications
> >        (goto-char (point-min))
> >        (while (re-search-forward "^[ \t]*#\\+.*$" nil t)
> >          (goto-char (match-beginning 0))
> >          (unless (looking-at-p org-view-credentials-re)
> >            (put-text-property
> >             (1- (match-beginning 0)) (match-end 0) 'invisible
> visibility))
> >          (goto-char (match-end 0)))))))
> >
> > (defun org-view--update-properties (visibility)
> >   "Set invisible property to VISIBILITY for properties in the current
> buffer."
> >   (org-with-wide-buffer
> >    (save-excursion
> >      (with-silent-modifications
> >        (goto-char (point-min))
> >        (while (re-search-forward org-property-drawer-re nil t)
> >          (put-text-property
> >           (match-beginning 0) (match-end 0) 'invisible visibility))
> >        (goto-char (point-min))
> >        (while (re-search-forward "^[ \t]*#\\+PROPERTY:.*$" nil t)
> >          (put-text-property
> >           (1- (match-beginning 0)) (1+ (match-end 0)) 'invisible
> visibility))))))
> >
> > (defun org-view--update-stars (visibility)
> >   "Update invisible property to VISIBILITY for markers in the current
> buffer."
> >   (org-with-wide-buffer
> >    (save-excursion
> >      (goto-char (point-min))
> >      (with-silent-modifications
> >        (while (re-search-forward org-view-stars-re nil t)
> >          (put-text-property
> >           (match-beginning 0) (match-end 0) 'invisible visibility))))))
> >
> > (defun org-view--update-credentials (visibility)
> >   "Set invisible property to VISIBILITY for export settings."
> >   (org-with-wide-buffer
> >    (save-excursion
> >      (with-silent-modifications
> >        (goto-char (point-min))
> >        (while (re-search-forward org-view-credentials-re nil t)
> >          (put-text-property
> >           (match-beginning 0) (match-end 0) 'invisible visibility)
> >          (when org-view-center-credentials
> >            (org-view--center-in-window visibility)))
> >        (goto-char (point-min))))))
> >
> > (defun org-view--center-in-window (center)
> >   "Center a line in a window pixel wise."
> >   (save-excursion
> >     (goto-char (line-beginning-position))
> >     (let ((end (line-end-position))
> >           (beg (line-beginning-position)))
> >       (if center
> >           (let* ((line (buffer-substring beg end))
> >                  (length (/ (string-pixel-width line) 2)))
> >             (put-text-property
> >              beg (1+ beg) 'display `(space :align-to (- center
> (,length)))))
> >         (remove-text-properties beg (1+ beg) '(display nil))))))
> >
> > ;;;###autoload
> > (define-minor-mode org-view-hide-tags-mode
> >   "Hide/show tags in org-headings."
> >   :global nil :lighter " org-htm"
> >   (unless (derived-mode-p 'org-mode)
> >     (error "Not in org-mode"))
> >   (org-view--update-tags org-view-hide-tags-mode))
> >
> > ;;;###autoload
> > (define-minor-mode org-view-hide-stars-mode
> >   "Hide/show leading stars in org-headings."
> >   :global nil :lighter " org-hsm"
> >   (unless (derived-mode-p 'org-mode)
> >     (error "Not in org-mode"))
> >   (org-view--update-stars org-view-hide-stars-mode))
> >
> > ;;;###autoload
> > (define-minor-mode org-view-hide-keywords-mode
> >   "Hide/show leading stars in org-headings."
> >   :global nil :lighter " org-hkm"
> >   (unless (derived-mode-p 'org-mode)
> >     (error "Not in org-mode"))
> >   (org-view--update-keywords org-view-hide-stars-mode))
> >
> > ;;;###autoload
> > (define-minor-mode org-view-hide-properties-mode
> >   "Hide/show properties and property drawers."
> >   :global nil :lighter " org-hpm"
> >   (unless (derived-mode-p 'org-mode)
> >     (error "Not in org-mode"))
> >   (org-view--update-properties org-view-hide-properties-mode))
> >
> > ;;;###autoload
> > (define-minor-mode org-view-pretty-credentials-mode
> >   "Prettify credentials in org-buffers."
> >   :global nil :lighter " org-pcm"
> >   (unless (derived-mode-p 'org-mode)
> >     (error "Not in org-mode"))
> >   (org-view--update-credentials org-view-pretty-credentials-mode))
> >
> > (defun org-view-quit ()
> >   (interactive)
> >   (org-view-mode -1)
> >   (message "org-view mode disabled in current buffer"))
> >
> > (defvar-keymap org-view-mode-map
> >   :doc "Keymap for ‘ORG-view-mode’"
> >   "c" #'org-view-quit
> >   "C" #'org-view-quit
> >   "e" #'org-view-quit
> >   "E" #'org-view-quit
> >   "q" #'org-view-quit
> >   "Q" #'org-view-quit)
> >
> > ;;;###autoload
> > (define-minor-mode org-view-mode
> >   "Hide/show babel source code blocks on demand."
> >   :global nil :lighter " org-view" :keymap org-view-mode-map
> >   (unless (derived-mode-p 'org-mode)
> >     (error "Not in org-mode"))
> >   (cond (org-view-mode
> >          (org-view-hide-tags-mode org-view-mode)
> >          (org-view-hide-stars-mode org-view-mode)
> >          (org-view-hide-keywords-mode org-view-mode)
> >          (org-view-hide-properties-mode org-view-mode)
> >          (org-view-pretty-credentials-mode org-view-mode)
> >          (when org-view-diminish-mode
> >            (dolist (mode '(org-view-hide-tags-mode
> >                            org-view-hide-stars-mode
> >                            org-view-hide-keywords-mode
> >                            org-view-hide-properties-mode
> >                            org-view-pretty-credentials-mode))
> >              (let ((mode-str (cdr (assq mode minor-mode-alist))))
> >                (setcar mode-str ""))))
> >          (view-mode +1))
> >         (t (view-mode -1)
> >            (org-view-hide-tags-mode -1)
> >            (org-view-hide-stars-mode -1)
> >            (org-view-hide-keywords-mode -1)
> >            (org-view-hide-properties-mode -1)
> >            (org-view-pretty-credentials-mode -1))))
> >
> > (provide 'org-view-mode)
> >
> > ;;; org-view-mode.el ends here
>
>
>
> ------------------------------------------------------------------
> Russell Adams                            RLAdams@AdamsInfoServ.com
>
> PGP Key ID:     0x1160DCB3           http://www.adamsinfoserv.com/
>
> Fingerprint:    1723 D8CA 4280 1EC9 557F  66E8 1154 E018 1160 DCB3
>
>

[-- Attachment #2: Type: text/html, Size: 13874 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Read only org view mode
  2022-01-24 11:40   ` Neil Jerram
@ 2022-01-24 12:58     ` Russell Adams
  0 siblings, 0 replies; 6+ messages in thread
From: Russell Adams @ 2022-01-24 12:58 UTC (permalink / raw)
  To: emacs-orgmode

On Mon, Jan 24, 2022 at 11:40:05AM +0000, Neil Jerram wrote:
> On Mon, 24 Jan 2022, 11:14 Russell Adams, <RLAdams@adamsinfoserv.com> wrote:
>
> > Why not just do an ASCII export to a temporary read only buffer for
> > viewing?
>
> Do you mean that you're agreeing with the concept, but finding the
> implementation unnecessarily complicated?

I'm not being negative about the concept. I'm asking if the poster had
considered using the built-in tools before creating another new
library.

I did a short look at the site and the assertion "view org with less
markup", and that was my first impression.

I had two thoughts. The first was if the markup is a problem and you
want a read only view, why not use the built in ascii export to a
buffer and view that buffer? I just hit C-c C-e t A and M-x
read-only-mode and was able to navigate my ascii org file as a read
only buffer.

Second thought was that Org's syntax was supposed to minimize the
markup so it didn't negatively impact reading. Maybe the poster is
identifying a pain point we should be aware of as a community, ie:
that too much markup makes it hard to read.

My impression is only property drawers and source blocks are
potentially visually loud compared to the other markup. Timestamps are
pretty minimal and links already only show a descriptive text instead
of the full [[]] syntax.


------------------------------------------------------------------
Russell Adams                            RLAdams@AdamsInfoServ.com

PGP Key ID:     0x1160DCB3           http://www.adamsinfoserv.com/

Fingerprint:    1723 D8CA 4280 1EC9 557F  66E8 1154 E018 1160 DCB3


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-24 13:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-23  7:19 Read only org view mode Arthur Miller
2022-01-24  6:20 ` Marcin Borkowski
2022-01-24 10:30 ` Neil Jerram
2022-01-24 11:11 ` Russell Adams
2022-01-24 11:40   ` Neil Jerram
2022-01-24 12:58     ` Russell Adams

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).