Coder Social home page Coder Social logo

valign's Introduction

Valign.el

中文 README

This package provides visual alignment for Org Mode, Markdown and table.el tables on GUI Emacs. It can properly align tables containing variable-pitch font, CJK characters and images. Meanwhile, the text-based alignment generated by Org mode (or Markdown mode) is left untouched.

To use this package, load it and add valign-mode to org-mode-hook or markdown-mode-hook:

(add-hook 'org-mode-hook #'valign-mode)

./default.png

./table.el.png

Known problems:

  • Hidden links in markdown still occupy the full length of the link, because it uses character composition which we don’t support now.
  • Rendering large tables (≥100 lines) is laggy.

Note:

For table.el tables to work with valign, each cell has to have at least one space on the right and no space on the left. You can use ftable.el to auto-layout the table for you.

Install

You can obtain valign.el from GNU ELPA by typing:

M-x package-install RET valign RET

Customization

Set valign-fancy-bar to non-nil:

./fancy-bar.png

This only affects Org Mode and Markdown tables.

By default, valign doesn’t re-align the table after normal edit commands like self-insert-command and backward-kill-word. If you want valign to not re-align the table after a certain command, add that command to valign-not-align-after-list.

Because valign isn’t particularly efficient, it doesn’t align tables larger than 4000 characters in size. If you want to change that behavior, customize valign-max-table-size. Valign puts valign-table-fallback face on those large tables.

Other (less interesting) customization:

  • valign-signal-parse-error: Set to non-nil to be informed of parse errors.
  • valign-lighter: Lighter in mode-line.
  • valign-box-charset-alist: Used for defining table.el tables, e.g., Unicode/ASCII tables.

If function advice makes you itch

valign-mode adds advice and doesn’t remove them even if you close valign-mode because function advice is global and valign-mode is local. If you want to remove the advice, use valign-remove-advice. If you run this while some buffer still has valign-mode on, they break.

valign's People

Contributors

casouri avatar ksqsf avatar monnier avatar tumashu avatar willbchang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

valign's Issues

messing up with unordered lists

when valign mode is enabled, unordered lists starting with + get rendered as in tables.

+ aaa
+ bbb
+ ccc

gets
图片

if valign mode is turned off, they are rendered correctly
图片

PS: Though I have not tested, this might also conflict with org-superstar-prettify-item-bullets

Merge with org mode

If those known issues were resolved, I don't see any reasons why this should not come bundled with org-mode. I suggest coordinating with the team behind org-mode and see if that's feasible.

wrong-type-argument wholenump -1

Try on the master version and got the error while try to open your test.org file: (wrong-type-argument wholenump -1)

Here is the trace:

Debugger entered--Lisp error: (wrong-type-argument wholenump -1)
make-string(-1 9472)
valign--align-separator-row-full((-36 36 36 72) (1 2 3) "\n+-++\n| ||\n+-++\n+-++" -36)
valign--table-2()
valign-table-maybe(nil t)
valign-region()
valign--buffer-advice()
valign--org-indent-advice()
apply(valign--org-indent-advice nil)
org-indent-initialize-agent()
apply(org-indent-initialize-agent nil)
timer-event-handler([t 0 0 200000 t org-indent-initialize-agent nil idle 0])

I am using Emacs 27.1 and Doom-emacs on MacOS.

README: Installation with quelpa-use-package

I suggest to include the following snippet in the installation part of the README so that quelpa-use-package user could benefit it.

   (use-package valign
     :quelpa (valign :fetcher github :repo "casouri/valign")
     :ensure t
     :config
     (add-hook 'org-mode-hook #'valign-mode) 
     (setq align-fancy-bar t))

Table messed up when displaying line number

Test environment: doom sandbox's vanilla Doom.
valign version: 3.0.0

Debugger entered--Lisp error: (wrong-type-argument wholenump -4)
  make-string(-4 9472)
  valign--align-separator-row-full((-28 112 84 112) (1 2 3) "\n+-++\n| ||\n+-++\n+-++" -28)
  valign--table-2()
  valign-table-maybe(nil t)
  valign-region(2086 2586)
  #f(compiled-function (fun) #<bytecode 0x1fe1b129f04d>)(valign-region)
  run-hook-wrapped(#f(compiled-function (fun) #<bytecode 0x1fe1b129f04d>) valign-region)
  jit-lock--run-functions(2086 2586)
  jit-lock-fontify-now(2086 2586)
  jit-lock-function(2086)
  redisplay_internal\ \(C\ function\)()
  redisplay()
  sit-for(2)
  execute-extended-command(nil "valign-mode" #("valign-mod" 0 10 (ws-butler-chg chg)))
  funcall-interactively(execute-extended-command nil "valign-mode" #("valign-mod" 0 10 (ws-butler-chg chg)))
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

Emacs hangs opening org files with complex tables

I'm a heavy user of tables in org mode. Some of the tables I use have org mode html links, which from a comment on the description page I think might be incompatible with valign.

In any case, I thought I should report that I had a problem using valign severe enough that Emacs would hang when visiting an org file with such tables. In some cases, I could partially recover by hitting ctrl-g enough times, but after this, Emacs would have very laggy behavior and did not display tables correctly. (No white space was added, so there was no column alignment.) In other cases, I had to resort to OS-level force-quit (this is macOS).

The fact that the problem was due to links in the table is just my guess. I haven't taken the time to investigate this carefully. I could try to produce a MWE if you think it would be helpful.

args-out-of-range on org-journal-new-entry

Debugger entered--Lisp error: (args-out-of-range 0 255)
  put-text-property(0 255 fontified nil)
  valign--flag-region-advice(0 255 nil)
  apply(valign--flag-region-advice (0 255 nil))
  outline-flag-region(0 255 nil)
  outline-show-entry()
  outline-hide-other()
  org-journal--finalize-view()
  org-journal--goto-entry((3 2 2021))
  org-journal--open-entry(t t)
  org-journal--carryover()
  org-journal-new-entry(nil)
  funcall-interactively(org-journal-new-entry nil)
  call-interactively(org-journal-new-entry record nil)
  command-execute(org-journal-new-entry record)
  execute-extended-command(nil "org-journal-new-entry" "org jou")
  funcall-interactively(execute-extended-command nil "org-journal-new-entry" "org jou")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

alignment with org =verbatim= or ~code~ formatting

alignment of tables containing =verbatim= or code doesn't work for me, not sure if its just my config tho. i'm also unsure if it depends on how such faces are set. i tried removing my Height: and Family: settings but still didn't seem to work.

Org agenda clockreport valign not working

以前这样的配置是可以工作的,但是 org 升级到20210419 之后,这样不工作

     (use-package valign
	:custom
	(valign-fancy-bar 't)
	:hook
	(org-agenda-clockreport-mode . valign-mode)
	(org-agenda-finalize . valign-region)
	(org-agenda-mode . valign-mode))

valign error on dot source block

Here is an test org content which caused bellowing error:

* Email

#+begin_src dot :dir "data/images" :file Mail_server.png :cmdline -Kdot -Tpng
  +---------+  SMTP  +---+   +---+               +----------------+
  |Other MTA| <----> |MTA| --|MDA|-> Storage <-- |POP3/IMAP server|
  +---------+        +---+   +---+               +----------------+
                       ^                                 ^
                       |     SMTP    +---+               |
                       +-------------|MUA|---------------+
                                     +---+
#+end_src

And here is the error:

  +(528 nil 28 28)
  (setq pos (+ pos col-width bar-width ssw))
  (let* ((col-width (nth column-idx column-width-list)) (cell-width (valign--cell-width)) tab-width tab-start tab-end) (if ssw nil (setq ssw (valign--pixel-width-from-to (point) (1+ (point))))) (if bar-width nil (setq bar-width (valign--pixel-width-from-to (1- (point)) (point)))) (if (eq column-idx 0) (progn (if (valign--separator-p) (progn (setq separator-row-point-list (cons (point) separator-row-point-list)))) (valign--maybe-render-bar (1- (point))) (if (valign--separator-p) nil (setq rev-list nil)) (setq at-sep-row (if (valign--separator-p) t nil)) (setq pos (valign--pixel-width-from-to (line-beginning-position) (point))))) (cond ((eq cell-width 0) (setq tab-start (point)) (valign--skip-space-forward) (if (< (- (point) tab-start) 2) (valign--put-text-property tab-start (point) (+ pos col-width ssw)) (valign--put-text-property tab-start (1+ tab-start) (+ pos (/ col-width 2) ssw)) (valign--put-text-property (1+ tab-start) (point) (+ pos col-width ssw)))) ((valign--separator-p) nil) (t (let* ((val (valign--cell-alignment (valign--guess-table-type) (nth column-idx column-alignment-list)))) (cond ((eq val 'left) (search-forward "|" nil t) (backward-char) (setq tab-end (point)) (valign--skip-space-backward) (valign--put-text-property (point) tab-end (+ pos col-width ssw))) ((eq val 'right) (setq tab-width (- col-width cell-width)) (valign--put-text-property (point) (1+ ...) (+ pos tab-width))) (t nil))))) (setq pos (+ pos col-width bar-width ssw)) (if at-sep-row nil (setq rev-list (cons (- pos bar-width) rev-list))))
  (progn (valign--maybe-render-bar right-bar-pos) (let* ((col-width (nth column-idx column-width-list)) (cell-width (valign--cell-width)) tab-width tab-start tab-end) (if ssw nil (setq ssw (valign--pixel-width-from-to (point) (1+ (point))))) (if bar-width nil (setq bar-width (valign--pixel-width-from-to (1- (point)) (point)))) (if (eq column-idx 0) (progn (if (valign--separator-p) (progn (setq separator-row-point-list (cons ... separator-row-point-list)))) (valign--maybe-render-bar (1- (point))) (if (valign--separator-p) nil (setq rev-list nil)) (setq at-sep-row (if (valign--separator-p) t nil)) (setq pos (valign--pixel-width-from-to (line-beginning-position) (point))))) (cond ((eq cell-width 0) (setq tab-start (point)) (valign--skip-space-forward) (if (< (- (point) tab-start) 2) (valign--put-text-property tab-start (point) (+ pos col-width ssw)) (valign--put-text-property tab-start (1+ tab-start) (+ pos (/ col-width 2) ssw)) (valign--put-text-property (1+ tab-start) (point) (+ pos col-width ssw)))) ((valign--separator-p) nil) (t (let* ((val (valign--cell-alignment ... ...))) (cond ((eq val ...) (search-forward "|" nil t) (backward-char) (setq tab-end ...) (valign--skip-space-backward) (valign--put-text-property ... tab-end ...)) ((eq val ...) (setq tab-width ...) (valign--put-text-property ... ... ...)) (t nil))))) (setq pos (+ pos col-width bar-width ssw)) (if at-sep-row nil (setq rev-list (cons (- pos bar-width) rev-list)))))
  (if (save-excursion (search-forward "|" (line-end-position) t) (setq right-bar-pos (match-beginning 0))) (progn (valign--maybe-render-bar right-bar-pos) (let* ((col-width (nth column-idx column-width-list)) (cell-width (valign--cell-width)) tab-width tab-start tab-end) (if ssw nil (setq ssw (valign--pixel-width-from-to (point) (1+ (point))))) (if bar-width nil (setq bar-width (valign--pixel-width-from-to (1- (point)) (point)))) (if (eq column-idx 0) (progn (if (valign--separator-p) (progn (setq separator-row-point-list ...))) (valign--maybe-render-bar (1- (point))) (if (valign--separator-p) nil (setq rev-list nil)) (setq at-sep-row (if (valign--separator-p) t nil)) (setq pos (valign--pixel-width-from-to (line-beginning-position) (point))))) (cond ((eq cell-width 0) (setq tab-start (point)) (valign--skip-space-forward) (if (< (- ... tab-start) 2) (valign--put-text-property tab-start (point) (+ pos col-width ssw)) (valign--put-text-property tab-start (1+ tab-start) (+ pos ... ssw)) (valign--put-text-property (1+ tab-start) (point) (+ pos col-width ssw)))) ((valign--separator-p) nil) (t (let* ((val ...)) (cond (... ... ... ... ... ...) (... ... ...) (t nil))))) (setq pos (+ pos col-width bar-width ssw)) (if at-sep-row nil (setq rev-list (cons (- pos bar-width) rev-list))))))
  (save-excursion (if (save-excursion (search-forward "|" (line-end-position) t) (setq right-bar-pos (match-beginning 0))) (progn (valign--maybe-render-bar right-bar-pos) (let* ((col-width (nth column-idx column-width-list)) (cell-width (valign--cell-width)) tab-width tab-start tab-end) (if ssw nil (setq ssw (valign--pixel-width-from-to (point) (1+ ...)))) (if bar-width nil (setq bar-width (valign--pixel-width-from-to (1- ...) (point)))) (if (eq column-idx 0) (progn (if (valign--separator-p) (progn ...)) (valign--maybe-render-bar (1- ...)) (if (valign--separator-p) nil (setq rev-list nil)) (setq at-sep-row (if ... t nil)) (setq pos (valign--pixel-width-from-to ... ...)))) (cond ((eq cell-width 0) (setq tab-start (point)) (valign--skip-space-forward) (if (< ... 2) (valign--put-text-property tab-start ... ...) (valign--put-text-property tab-start ... ...) (valign--put-text-property ... ... ...))) ((valign--separator-p) nil) (t (let* (...) (cond ... ... ...)))) (setq pos (+ pos col-width bar-width ssw)) (if at-sep-row nil (setq rev-list (cons (- pos bar-width) rev-list)))))))
  (progn (save-excursion (if (save-excursion (search-forward "|" (line-end-position) t) (setq right-bar-pos (match-beginning 0))) (progn (valign--maybe-render-bar right-bar-pos) (let* ((col-width (nth column-idx column-width-list)) (cell-width (valign--cell-width)) tab-width tab-start tab-end) (if ssw nil (setq ssw (valign--pixel-width-from-to ... ...))) (if bar-width nil (setq bar-width (valign--pixel-width-from-to ... ...))) (if (eq column-idx 0) (progn (if ... ...) (valign--maybe-render-bar ...) (if ... nil ...) (setq at-sep-row ...) (setq pos ...))) (cond ((eq cell-width 0) (setq tab-start ...) (valign--skip-space-forward) (if ... ... ... ...)) ((valign--separator-p) nil) (t (let* ... ...))) (setq pos (+ pos col-width bar-width ssw)) (if at-sep-row nil (setq rev-list (cons ... rev-list))))))))
  (if (looking-at "[^|]*\n") (setq column-idx -1) (progn (save-excursion (if (save-excursion (search-forward "|" (line-end-position) t) (setq right-bar-pos (match-beginning 0))) (progn (valign--maybe-render-bar right-bar-pos) (let* ((col-width ...) (cell-width ...) tab-width tab-start tab-end) (if ssw nil (setq ssw ...)) (if bar-width nil (setq bar-width ...)) (if (eq column-idx 0) (progn ... ... ... ... ...)) (cond (... ... ... ...) (... nil) (t ...)) (setq pos (+ pos col-width bar-width ssw)) (if at-sep-row nil (setq rev-list ...))))))))
  (while (and (setq column-idx (1+ column-idx)) (search-forward "|" nil t) (< (point) end)) (if (looking-at "[^|]*\n") (setq column-idx -1) (progn (save-excursion (if (save-excursion (search-forward "|" (line-end-position) t) (setq right-bar-pos (match-beginning 0))) (progn (valign--maybe-render-bar right-bar-pos) (let* (... ... tab-width tab-start tab-end) (if ssw nil ...) (if bar-width nil ...) (if ... ...) (cond ... ... ...) (setq pos ...) (if at-sep-row nil ...))))))))
  (progn (setq column-idx -1) (while (and (setq column-idx (1+ column-idx)) (search-forward "|" nil t) (< (point) end)) (if (looking-at "[^|]*\n") (setq column-idx -1) (progn (save-excursion (if (save-excursion (search-forward "|" ... t) (setq right-bar-pos ...)) (progn (valign--maybe-render-bar right-bar-pos) (let* ... ... ... ... ... ... ...))))))))
  (let (end column-width-list column-idx pos ssw bar-width separator-row-point-list rev-list column-alignment-list info at-sep-row right-bar-pos) (if (not (valign--at-table-p)) (signal 'valign-not-on-table nil)) (valign--end-of-table) (setq end (point)) (valign--beginning-of-table) (valign--clean-text-property (point) end) (setq info (valign--calculate-table-info end)) (setq column-width-list (progn (or (and (memq (type-of info) cl-struct-valign-table-info-tags) t) (signal 'wrong-type-argument (list 'valign-table-info info))) (aref info 1)) column-alignment-list (progn (or (and (memq (type-of info) cl-struct-valign-table-info-tags) t) (signal 'wrong-type-argument (list 'valign-table-info info))) (aref info 2))) (progn (setq column-idx -1) (while (and (setq column-idx (1+ column-idx)) (search-forward "|" nil t) (< (point) end)) (if (looking-at "[^|]*\n") (setq column-idx -1) (progn (save-excursion (if (save-excursion ... ...) (progn ... ...))))))) (let ((--dolist-tail-- separator-row-point-list)) (while --dolist-tail-- (let ((row-point (car --dolist-tail--))) (goto-char row-point) (valign--align-separator-row (valign--guess-table-type) valign-separator-row-style (reverse rev-list)) (setq --dolist-tail-- (cdr --dolist-tail--))))))
  (save-excursion (let (end column-width-list column-idx pos ssw bar-width separator-row-point-list rev-list column-alignment-list info at-sep-row right-bar-pos) (if (not (valign--at-table-p)) (signal 'valign-not-on-table nil)) (valign--end-of-table) (setq end (point)) (valign--beginning-of-table) (valign--clean-text-property (point) end) (setq info (valign--calculate-table-info end)) (setq column-width-list (progn (or (and (memq (type-of info) cl-struct-valign-table-info-tags) t) (signal 'wrong-type-argument (list 'valign-table-info info))) (aref info 1)) column-alignment-list (progn (or (and (memq (type-of info) cl-struct-valign-table-info-tags) t) (signal 'wrong-type-argument (list 'valign-table-info info))) (aref info 2))) (progn (setq column-idx -1) (while (and (setq column-idx (1+ column-idx)) (search-forward "|" nil t) (< (point) end)) (if (looking-at "[^|]*\n") (setq column-idx -1) (progn (save-excursion (if ... ...)))))) (let ((--dolist-tail-- separator-row-point-list)) (while --dolist-tail-- (let ((row-point (car --dolist-tail--))) (goto-char row-point) (valign--align-separator-row (valign--guess-table-type) valign-separator-row-style (reverse rev-list)) (setq --dolist-tail-- (cdr --dolist-tail--)))))))
  (condition-case nil (save-excursion (let (end column-width-list column-idx pos ssw bar-width separator-row-point-list rev-list column-alignment-list info at-sep-row right-bar-pos) (if (not (valign--at-table-p)) (signal 'valign-not-on-table nil)) (valign--end-of-table) (setq end (point)) (valign--beginning-of-table) (valign--clean-text-property (point) end) (setq info (valign--calculate-table-info end)) (setq column-width-list (progn (or (and (memq ... cl-struct-valign-table-info-tags) t) (signal 'wrong-type-argument (list ... info))) (aref info 1)) column-alignment-list (progn (or (and (memq ... cl-struct-valign-table-info-tags) t) (signal 'wrong-type-argument (list ... info))) (aref info 2))) (progn (setq column-idx -1) (while (and (setq column-idx (1+ column-idx)) (search-forward "|" nil t) (< (point) end)) (if (looking-at "[^|]*\n") (setq column-idx -1) (progn (save-excursion ...))))) (let ((--dolist-tail-- separator-row-point-list)) (while --dolist-tail-- (let ((row-point ...)) (goto-char row-point) (valign--align-separator-row (valign--guess-table-type) valign-separator-row-style (reverse rev-list)) (setq --dolist-tail-- (cdr --dolist-tail--))))))) ((debug valign-bad-cell valign-not-gui valign-not-on-table) nil))
  valign-table()
  (condition-case err (valign-table) ((debug error) (message "Valign error when aligning table: %s" (error-message-string err))))
  valign-table-quiet()
  (while (and (search-forward "|" nil t) (< (point) end)) (valign-table-quiet) (valign--end-of-table))
  (save-excursion (goto-char beg) (while (and (search-forward "|" nil t) (< (point) end)) (valign-table-quiet) (valign--end-of-table)) (let* ((modified (buffer-modified-p)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-modification-hooks t)) (unwind-protect (progn (put-text-property beg (point) 'valign-init t)) (if modified nil (restore-buffer-modified-p nil)))))
  (progn (save-excursion (goto-char beg) (while (and (search-forward "|" nil t) (< (point) end)) (valign-table-quiet) (valign--end-of-table)) (let* ((modified (buffer-modified-p)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-modification-hooks t)) (unwind-protect (progn (put-text-property beg (point) 'valign-init t)) (if modified nil (restore-buffer-modified-p nil))))))
  (if (window-live-p (get-buffer-window nil (selected-frame))) (progn (save-excursion (goto-char beg) (while (and (search-forward "|" nil t) (< (point) end)) (valign-table-quiet) (valign--end-of-table)) (let* ((modified (buffer-modified-p)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-modification-hooks t)) (unwind-protect (progn (put-text-property beg (point) 'valign-init t)) (if modified nil (restore-buffer-modified-p nil)))))))
  (let ((beg (or beg (point-min))) (end (or end (point-max)))) (if (window-live-p (get-buffer-window nil (selected-frame))) (progn (save-excursion (goto-char beg) (while (and (search-forward "|" nil t) (< (point) end)) (valign-table-quiet) (valign--end-of-table)) (let* ((modified (buffer-modified-p)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-modification-hooks t)) (unwind-protect (progn (put-text-property beg ... ... t)) (if modified nil (restore-buffer-modified-p nil))))))))
  valign-region(292072 293072)
  #f(compiled-function (fun) #<bytecode 0x5b87da0901fa235>)(valign-region)
  run-hook-wrapped(#f(compiled-function (fun) #<bytecode 0x5b87da0901fa235>) valign-region)
  jit-lock--run-functions(292072 293072)
  jit-lock-fontify-now(292072 293072)
  jit-lock-function(292072)
  redisplay_internal\ \(C\ function\)()
  redisplay()
  sit-for(0)
  ispell-init-process()
  ispell-buffer-local-words()
  ispell-accept-buffer-local-defs()
  flyspell-accept-buffer-local-defs(force)
  flyspell-mode-on()
  flyspell-mode(1)
  flyspell-prog-mode()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook lisp-data-mode-hook emacs-lisp-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook lisp-data-mode-hook emacs-lisp-mode-hook))
  run-mode-hooks(emacs-lisp-mode-hook)
  emacs-lisp-mode()
  set-auto-mode-0(emacs-lisp-mode nil)
  set-auto-mode()
  normal-mode(t)
  after-find-file(nil nil)
  find-file-noselect-1(#<buffer init.el> "~/.config/emacs/init.el" :nowarn nil "~/Git/dotfiles/.config/emacs/init.el" (6555408 66308))
  find-file-noselect("/home/stardiviner/.config/emacs/init.el" :nowarn)
  desktop-restore-file-buffer("/home/stardiviner/.config/emacs/init.el" "init.el" nil)
  desktop-create-buffer(208 "/home/stardiviner/.config/emacs/init.el" "init.el" emacs-lisp-mode (eldoc-mode override-global-mode outline-minor-mode global-auto-revert-mode magit-file-mode edebug-inline-result-mode bug-reference-prog-mode org-edna-mode aggressive-indent-mode projectile-mode rainbow-delimiters-mode company-mode flyspell-mode git-gutter+-mode eldoc-overlay-mode subword-mode paredit-mode hl-todo-mode zoom-mode ivy-mode counsel-mode yas-minor-mode dap-mode TeX-PDF-mode) 8999 (nil nil) nil nil ((buffer-display-time 24345 44669 91564 939000) (buffer-file-coding-system . prefer-utf-8-unix)) ((mark-ring nil)))
  eval-buffer(#<buffer  *load*> nil "/home/stardiviner/.config/emacs/desktop-save/.emacs.desktop" nil t)  ; Reading at buffer position 23855
  load-with-code-conversion("/home/stardiviner/.config/emacs/desktop-save/.emac..." "/home/stardiviner/.config/emacs/desktop-save/.emac..." t t)
  load("/home/stardiviner/.config/emacs/desktop-save/.emac..." t t t)
  desktop-read()
  #f(compiled-function () #<bytecode -0xc5cd74a26b1b456>)()
  run-hooks(after-init-hook delayed-warnings-hook)
  command-line()
  normal-top-level()

Some errors: Wrong type argument: number-or-marker-p, nil

When I enabled valign-mode on Org Mode buffer, I got following error.

valign--glyph-width-at-point: Wrong type argument: number-or-marker-p, nil
nil
Mark set [2 times]
Configuring package visual-regexp...done
Configuring package visual-regexp...done
Mark saved where search started
Configuring package symbol-overlay...done
valign--glyph-width-at-point
Valign expects one space between the cell’s content and either the left bar or the right bar, but this cell seems to violate that assumption [3 times]
valign-table: Wrong type argument: number-or-marker-p, nil
Valign expects one space between the cell’s content and either the left bar or the right bar, but this cell seems to violate that assumption [3 times]
valign-table: Wrong type argument: number-or-marker-p, nil
Mark activated

Column misaligned when org table is within an item list

When table is within an item list, columns appear misaligned.

Capture

If the table begins at first column, the misalignments disappear.

I use the org-indent-mode, but the issue persists if it is turned off.
I also use the mixed-pitch-mode, but this one should use a fixed font for tables.

What could be the problem ?

Regards

prefer hooks over advice

valign/valign.el

Lines 914 to 934 in 16e3313

(dolist (fn '(org-cycle
;; Why this function? If you tab into an org
;; field (cell) and start typing right away,
;; org clears that field for you with this
;; function. The problem is, this functions
;; messes up the overlay and makes the bar
;; invisible. So we have to fix the overlay
;; after this function.
org-table-blank-field
markdown-cycle))
(advice-add fn :after #'valign--tab-advice))
(dolist (fn '(text-scale-increase
text-scale-decrease
org-agenda-finalize-hook
org-toggle-inline-images))
(advice-add fn :after #'valign--buffer-advice))
(dolist (fn '(org-flag-region outline-flag-region))
(advice-add fn :after #'valign--flag-region-advice))
(with-eval-after-load 'org-indent
(advice-add 'org-indent-initialize-agent
:after #'valign--org-indent-advice))

Instead of adding advice after each of these commands, it may be better to implement a function which can be run, buffer-locally, during post-command-hook. You could store the commands and their associated functions in an alist, and query that during post-command-hook using this-command. Proof of concept:

;;commands here would be a defcustom in an actual library.
(let ((commands '((self-insert-command . (lambda () (message "hi"))))))
  (defun concept ()
    (when-let ((post (alist-get this-command commands)))
      (funcall post))))

(add-hook 'post-command-hook #'concept nil t)

[Feature request] Top and bottom borders for org tables.

Hi. Org-mode table syntax is a bit weird when it comes to borders. However, it's probably possible to make it look like normal table. What I mean: table top and bottom border vertical lines stick out of table. So my request is to somehow make valign recognize top and bottom lines and make them different from rest so they not stick out. I tried to do it but it's not simple for me, as I don't know how to program in elisp. The most difficult task however might be to find way to format | or this strange inverted space hack (fancy bar, which I use btw) in code to be half width.

to be more specific, here's example table:

|-----------|---|---|
|something|xyz|xyz|
|-----------|---|---|

cannot parse tables with TBLFM

when table has TBLFM entry, valign produce the following error:

Valign cannot parse the table: "Missing rows or columns"

This is an example table that can produce this error:

#+TITLE: Test


| 项目 1 | 项目 2 | 项目 3 | 共计 |
|--------+--------+--------+------|
|    1.1 |    2.2 |    3.3 | 6.6  |
#+TBLFM: $4=$1+$2+$3

edit an org file without table would got errors

When openning an org file without table. it will get the errors as below when moving cursor.
Everything is fine when I input a table in current org buffer.

Error running timer ‘org-indent-initialize-agent’: (wrong-type-argument number-or-marker-p nil) [3 times]

Emacs 27.1 and Emacs 28.0.50
Arch Linux or Win 10

Roll back to commit 8c28c8c works well.

(void-function beg)

For a reason I don't understand, org-table-next-field on the table

| a | b | c |

gives me the following error :

Debugger entered--Lisp error: (void-function beg)
  beg(294)
  valign--tab-advice(#("a" 0 1 (fontified t valign-init t cursor-sensor-functions nil face org-table)) 1 "l")
  apply(valign--tab-advice (#("a" 0 1 (fontified t valign-init t cursor-sensor-functions nil face org-table)) 1 "l"))
  org-table--align-field(#("a" 0 1 (fontified t valign-init t cursor-sensor-functions nil face org-table)) 1 "l")
  apply(org-table--align-field (#("a" 0 1 (fontified t valign-init t cursor-sensor-functions nil face org-table)) 1 "l"))
  cl--mapcar-many(org-table--align-field ((#("a" 0 1 (fontified t valign-init t cursor-sensor-functions nil face org-table)) #("b" 0 1 (fontified t valign-init t cursor-sensor-functions nil face org-table)) #("c" 0 1 (fontified t valign-init t cursor-sensor-functions nil face org-table))) (1 1 1) ("l" "l" "l")) accumulate)
  cl-mapcar(org-table--align-field (#("a" 0 1 (fontified t valign-init t cursor-sensor-functions nil face org-table)) #("b" 0 1 (fontified t valign-init t cursor-sensor-functions nil face org-table)) #("c" 0 1 (fontified t valign-init t cursor-sensor-functions nil face org-table))) (1 1 1) ("l" "l" "l"))
  org-table-align()
  org-table-next-field()
  funcall-interactively(org-table-next-field)
  call-interactively(org-table-next-field)
  org-cycle(nil)
  funcall-interactively(org-cycle nil)
  call-interactively(org-cycle nil nil)
  command-execute(org-cycle)

I failed to understand why by looking at the source code...

Fontifying large table is laggy as well

The README says that

Editing large tables (≥100 lines) is a bit laggy.

However, it's not limited to editing. Fontifying a table is laggy as well.

Example in org-mode:

* A folded section with a large table

(org-cycle) for the first time the section takes some seconds.

inline latex preview cannot align properly

There is auctually 2 problems.

1. some tables cannot align properly.

Screenshot_20200816_130113

2. valign-mode conflicts org-latex-preview on the org-mode-hook

suppose I add the following function on org-mode-hook:

(add-hook 'org-mode-hook
  (lambda ()
    (interactive)
    (when org-mode-hook
      (org-latex-preview '(16))))
  )

and the value of org-mode-hook, which will load valign-mode afterwise:

(+org-refresh-latex-background-h
 org-edit-latex-mode
 (lambda nil
  (interactive)
  (org-latex-preview
   '(16)))
 valign-mode

...)

but the table woundn't rendered as expected, unless I manually un-preview, indent, then preview them, as the following gif shows(still has the first problem):
Peek 2020-08-16 12-52

  • my org-format-latex-options:
(:foreground default :background default :scale 2.0 :html-foreground "Black" :html-background "Transparent" :html-scale 1.0 :matchers
	     ("begin" "$1" "$" "$$" "\\(" "\\["))
  • font set:
    Sarasa Term SC

other information

  • system: x86-64 GNU/Linux
  • emacs: 28.0.50 native-comp branch

invalid-function (ch (char-after pos))

I get this when visiting org files.

Backtrace:

Debugger entered--Lisp error: (invalid-function (ch (char-after pos)))
  (ch (char-after pos))()
  valign--at-table-p()
  valign--beginning-of-table()
  valign-table-maybe(t)
  #f(compiled-function () (interactive nil) #<bytecode 0x12f3141>)()
  apply(#f(compiled-function () (interactive nil) #<bytecode 0x12f3141>) nil)
  #f(compiled-function (body &rest args) #<bytecode 0x5a3ba1>)(#f(compiled-function () (interactive nil) #<bytecode 0x12f3141>))
  apply(#f(compiled-function (body &rest args) #<bytecode 0x5a3ba1>) #f(compiled-function () (interactive nil) #<bytecode 0x12f3141>) nil)
  valign-table()
  eval((valign-table) t)
  eval-expression((valign-table) nil nil 127)
  funcall-interactively(eval-expression (valign-table) nil nil 127)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)

It works fine if valign--char-after-as-string doesn't use the if-let macro. As in

(defsubst valign--char-after-as-string (&optional pos)
  "Return (char-after POS) as a string."
  ;; (char-to-string (char-after)) doesn’t work because
  ;; ‘char-to-string’ doesn’t accept nil.b
  (let ((ch (char-after pos)))
    (if ch
        (char-to-string ch)
      nil)))

In GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0)
Windowing system distributor 'The X.Org Foundation', version 11.0.12010000
System Description: NixOS 21.05 (Okapi)

Devangari script sometimes breaks the alignment

For some strange reason the following table does get aligned janky, could you please investigate:

    | Hindi | Deutsch |
    |-------+---------|
    | एक    |         |
    | एकता  |         |
    | मेरा   |         |
    | बेकार  |         |
    | रेत    |         |

For me this looks like this:

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.