Org-mode mailing list
 help / color / mirror / Atom feed
* Include org-pretty-table by Matus Goljer (Fuco1) in org-mode
@ 2021-01-06 12:20 Arthur Miller
  2021-01-06 18:25 ` Uwe Brauer
  0 siblings, 1 reply; 2+ messages in thread
From: Arthur Miller @ 2021-01-06 12:20 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi guys,

Can we get org-pretty-table into org-mode?

https://github.com/Fuco1/org-pretty-table

It replaces ascii chars with unicode box-drawing characters.

It might be a bit rough around the edges, and Matus himself does not
seem to be currently interested to work on, but it seems to work
satisfying for me.

I would like to have it in org-mode by default as a coplement to
org-pretty-entities and inline images and links.

Attached is the latest source for those who don't like to download
themselves from Github.

I am not sure if I am the best person to work on this; I am not very
well acquainted with org-mode, but I can try to help as much as I can.


[-- Attachment #2: org-pretty-table.el --]
[-- Type: text/plain, Size: 8520 bytes --]

;;; org-pretty-table.el --- Replace org-table characters with box-drawing unicode glyphs.

;; Copyright (C) 2013 Matus Goljer

;; Author: Matus Goljer <matus.goljer@gmail.com>
;; Maintainer: Matus Goljer <matus.goljer@gmail.com>
;; Keywords: faces
;; Version: 0.0.1
;; Created: 29th November 2013

;; 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:

;; This replaces the characters - | and + in `org-mode' tables with
;; appropriate unicode box-drawing glyphs, see
;; http://en.wikipedia.org/wiki/Box-drawing_character

;;; Code:

(defconst org-pretty-table-regexp (regexp-opt '("-" "+" "|")))

(defsubst org-pretty-table-is-empty-line ()
  (memq (following-char) '(? 10 ?#)))

(defun org-pretty-table-propertize-region (start end)
  "Replace org-table characters with box-drawing unicode glyphs
between START and END.

Used by jit-lock for dynamic highlighting."
  (save-excursion
    (goto-char start)
    (let (table-end)
      (while (re-search-forward org-pretty-table-regexp end t)
        ;; reached the end of the current table
        (if (and table-end
                 (> (point) table-end))
            (setq table-end nil))

        ;; check if the current match is a table if we are not in a
        ;; table right now
        (unless (and (not table-end)
                     (not (save-match-data
                            (org-at-table-p))))

          ;; get the end of the table if we found a new table, so we
          ;; don't have to check (org-at-table-p) again until then
          (unless table-end
            (save-match-data
              (setq table-end (org-table-end))))
          
          ;; determine the context of the character
          (let ((match (match-string 0)))
            (cond
             ((equal "-" match)
              (backward-char 1)
              (re-search-forward "-+")
              (put-text-property (match-beginning 0) (match-end 0) 'display (make-string (- (match-end 0) (match-beginning 0)) ?─))
              t)
             ((equal "|" match)
              (cond
               ((and (eq (following-char) ?-)
                     (save-excursion
                       (forward-line 1)
                       (not (org-pretty-table-is-empty-line)))
                     (save-excursion
                       (forward-line -1)
                       (not (org-pretty-table-is-empty-line))))
                (put-text-property (match-beginning 0) (match-end 0) 'display "├")
                t)
               ((and (save-excursion
                       (backward-char 1)
                       (eq (preceding-char) ?-))
                     (save-excursion
                       (forward-line 1)
                       (not (org-pretty-table-is-empty-line)))
                     (save-excursion
                       (forward-line -1)
                       (not (org-pretty-table-is-empty-line))))
                (put-text-property (match-beginning 0) (match-end 0) 'display "┤")
                t)
               ((and (save-excursion
                       (backward-char 1)
                       (eq (preceding-char) ?-))
                     (save-excursion
                       (forward-line -1)
                       (org-pretty-table-is-empty-line)))
                (put-text-property (match-beginning 0) (match-end 0) 'display "┐")
                t)
               ((and (save-excursion
                       (backward-char 1)
                       (eq (preceding-char) ?-))
                     (save-excursion
                       (forward-line 1)
                       (org-pretty-table-is-empty-line)))
                (put-text-property (match-beginning 0) (match-end 0) 'display "┘")
                t)
               ((and (eq (following-char) ?-)
                     (save-excursion
                       (forward-line -1)
                       (org-pretty-table-is-empty-line)))
                (put-text-property (match-beginning 0) (match-end 0) 'display "┌")
                t)
               ((and (eq (following-char) ?-)
                     (save-excursion
                       (forward-line 1)
                       (org-pretty-table-is-empty-line)))
                (put-text-property (match-beginning 0) (match-end 0) 'display "└")
                t)
               (t
                (put-text-property (match-beginning 0) (match-end 0) 'display "│")
                t)))
             ((equal "+" match)
              (cond
               ((and (eq (following-char) ?-)
                     (save-excursion
                       (backward-char 1)
                       (eq (preceding-char) ?-))
                     (save-excursion
                       (let ((char-pos (- (point) (line-beginning-position) 1)))
                         (forward-line -1)
                         (beginning-of-line)
                         (forward-char char-pos))
                       (eq (following-char) ?|))
                     (save-excursion
                       (backward-char 1)
                       (next-line)
                       (eq (following-char) ?|)))
                (put-text-property (match-beginning 0) (match-end 0) 'display "┼")
                t)
               ((and (eq (following-char) ?-)
                     (save-excursion
                       (backward-char 1)
                       (eq (preceding-char) ?-))
                     (save-excursion
                       (backward-char 1)
                       (previous-line)
                       (memq (following-char) '(? 10)))
                     (save-excursion
                       (let ((char-pos (- (point) (line-beginning-position) 1)))
                         (forward-line 1)
                         (beginning-of-line)
                         (forward-char char-pos))
                       (eq (following-char) ?|)))
                (put-text-property (match-beginning 0) (match-end 0) 'display "┬")
                t)
               ((and (eq (following-char) ?-)
                     (save-excursion
                       (backward-char 1)
                       (eq (preceding-char) ?-))
                     (save-excursion
                       (let ((char-pos (- (point) (line-beginning-position) 1)))
                         (forward-line -1)
                         (beginning-of-line)
                         (forward-char char-pos))
                       (eq (following-char) ?|))
                     (save-excursion
                       (backward-char 1)
                       (next-line)
                       (or (memq (following-char) '(? 10))
                           (eq (char-after (line-beginning-position)) ?#))))
                (put-text-property (match-beginning 0) (match-end 0) 'display "┴")
                t))))))))))

(defun org-pretty-table-unpropertize-region (start end)
  "Remove box-drawing compositions between START and END."
  (remove-text-properties start end '(display)))

;;; Minor mode:

;;;###autoload
(define-minor-mode org-pretty-table-mode
  "Replace org-table characters with box-drawing unicode glyphs."
  :lighter " OPT"
  (if org-pretty-table-mode
      (jit-lock-register 'org-pretty-table-propertize-region t)
    (jit-lock-unregister 'org-pretty-table-propertize-region)
    (org-pretty-table-unpropertize-region (point-min) (point-max))))

;;;###autoload
(defun turn-on-org-pretty-table-mode ()
  (org-pretty-table-mode 1))

;;;###autoload
(defun turn-off-org-pretty-table-mode ()
  (org-pretty-table-mode 0))

;;;###autoload
(define-globalized-minor-mode global-org-pretty-table-mode
  org-pretty-table-mode turn-on-org-pretty-table-mode)

(provide 'org-pretty-table)
;;; org-pretty-table.el ends here

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

* Re: Include org-pretty-table by Matus Goljer (Fuco1) in org-mode
  2021-01-06 12:20 Include org-pretty-table by Matus Goljer (Fuco1) in org-mode Arthur Miller
@ 2021-01-06 18:25 ` Uwe Brauer
  0 siblings, 0 replies; 2+ messages in thread
From: Uwe Brauer @ 2021-01-06 18:25 UTC (permalink / raw)
  To: emacs-orgmode

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

>>> "AM" == Arthur Miller <arthur.miller@live.com> writes:

> Hi guys,
> Can we get org-pretty-table into org-mode?

> https://github.com/Fuco1/org-pretty-table

> It replaces ascii chars with unicode box-drawing characters.

That is indeed very nice. Why can't he start to put it in MELPA? Would
also make things easier.

Regards

Uwe Brauer 

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

end of thread, other threads:[~2021-01-06 18:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-06 12:20 Include org-pretty-table by Matus Goljer (Fuco1) in org-mode Arthur Miller
2021-01-06 18:25 ` Uwe Brauer

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git