Org mode 表格像素对齐

还有 | 在source block里面也出现报错的情况。我搜索了我Org大文件里面所有 | 的内容情形,方便测试。

* vertical line in source block

#+begin_src emacs-lisp
(defun my:proxy-toggle (proxy)
  "A command to toggle `PROXY' for Emacs."
  (interactive (list (unless my:proxy-toggle-p
                       (completing-read "Select a proxy routine: " '("socks" "url_proxy_services" "env HTTP_PROXY")))))
  (if my:proxy-toggle-p
      (setq my:proxy-toggle-p nil)
    (setq my:proxy-toggle-p proxy))
  (pcase my:proxy-toggle-p
    ("socks"
     (setq url-gateway-method 'socks
           socks-noproxy '("localhost")
           socks-server '("Default server" "127.0.0.1" 1086 5)))
    ("url_proxy_services"
     (setq url-proxy-services
           '(("http"  . "127.0.0.1:8118")
             ("https" . "127.0.0.1:8118")
             ("ftp"   . "127.0.0.1:8118")
             ;; don't use `localhost', avoid robe server (For Ruby) can't response.
             ("no_proxy" . "127.0.0.1")
             ("no_proxy" . "^.*\\(baidu\\|sina)\\.com")
             )))
    ("env HTTP_PROXY"
     ;; Privoxy
     (setenv "HTTP_PROXY"  "http://localhost:8118")
     (setenv "HTTPS_PROXY" "http://localhost:8118"))
    (_
     (setq url-gateway-method 'native)
     (setq url-proxy-services nil)
     (setenv "HTTP_PROXY"  nil)
     (setenv "HTTPS_PROXY" nil))
    ))
#+end_src

还有这个,也是 | 的问题。

* pipe in shell command

#+begin_src sh
pmap -d $(pidof emacs) | head -n 5
#+end_src
2. =[C-u M-|]= to run command on region

你是不是开了debug-on-error?

因为那个buffer没有开valign吧?我看看table.el,我总觉得之前看过table.el没有这么用的

是的,我在Emacs启动的过程中是开启了debug-on-error 的,等启动完成才设置为关闭。

#+begin_src eshell
clang -fsyntax-only -Xclang -ast-dump /tmp/demo.cpp
#+end_src

#+RESULTS:
#+begin_example
TranslationUnitDecl 0x557d0a3d5be8 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0x557d0a3d64c0 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'
| `-BuiltinType 0x557d0a3d6180 '__int128'
|-TypedefDecl 0x557d0a3d6530 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'
| `-BuiltinType 0x557d0a3d61a0 'unsigned __int128'
|-TypedefDecl 0x557d0a3d68a8 <<invalid sloc>> <invalid sloc> implicit __NSConstantString '__NSConstantString_tag'
| `-RecordType 0x557d0a3d6620 '__NSConstantString_tag'
|   `-CXXRecord 0x557d0a3d6588 '__NSConstantString_tag'
|-TypedefDecl 0x557d0a3d6940 <<invalid sloc>> <invalid sloc> implicit __builtin_ms_va_list 'char *'
| `-PointerType 0x557d0a3d6900 'char *'
|   `-BuiltinType 0x557d0a3d5c80 'char'
|-TypedefDecl 0x557d0a413bf8 <<invalid sloc>> <invalid sloc> implicit __builtin_va_list '__va_list_tag [1]'
| `-ConstantArrayType 0x557d0a413ba0 '__va_list_tag [1]' 1 
|   `-RecordType 0x557d0a3d6a30 '__va_list_tag'
|     `-CXXRecord 0x557d0a3d6998 '__va_list_tag'
|-FunctionDecl 0x557d0a413ca0 </tmp/demo.cpp:1:1, line:5:1> line:1:5 main 'int ()'
| `-CompoundStmt 0x557d0a414230 <col:12, line:5:1>
|   |-DeclStmt 0x557d0a413e50 <line:2:1, col:10>
|   | `-VarDecl 0x557d0a413dc8 <col:1, col:9> col:5 used a 'int' cinit
|   |   `-IntegerLiteral 0x557d0a413e30 <col:9> 'int' 0
|   |-CallExpr 0x557d0a4141a0 <line:3:1, col:27> 'int'
|   | |-ImplicitCastExpr 0x557d0a414188 <col:1> 'int (*)(const char *, ...)' <BuiltinFnToFnPtr>
|   | | `-DeclRefExpr 0x557d0a414070 <col:1> '<builtin fn type>' Function 0x557d0a413ef8 '__builtin_printf' 'int (const char *, ...)'
|   | |-ImplicitCastExpr 0x557d0a4141d0 <col:18> 'const char *' <ArrayToPointerDecay>
|   | | `-StringLiteral 0x557d0a414108 <col:18> 'const char [4]' lvalue "%d\n"
|   | `-ImplicitCastExpr 0x557d0a4141e8 <col:26> 'int' <LValueToRValue>
|   |   `-DeclRefExpr 0x557d0a414128 <col:26> 'int' lvalue Var 0x557d0a413dc8 'a' 'int'
|   `-ReturnStmt 0x557d0a414220 <line:4:1, col:8>
|     `-IntegerLiteral 0x557d0a414200 <col:8> 'int' 0
`-LinkageSpecDecl 0x557d0a413ea8 <line:3:1> col:1 implicit C
  `-FunctionDecl 0x557d0a413ef8 <col:1> col:1 implicit used __builtin_printf 'int (const char *, ...)' extern
    |-ParmVarDecl 0x557d0a413f98 <<invalid sloc>> <invalid sloc> 'const char *'
    `-FormatAttr 0x557d0a414008 <col:1> Implicit printf 1 2
#+end_example

上面这个org文件会提示

Debugger entered--Lisp error: (valign-not-on-table)
  signal(valign-not-on-table nil)
  valign-table()
  valign-table-quiet()
  valign-region(1 501)
  #f(compiled-function (fun) #<bytecode 0x58b8eea09c11c75>)(valign-region)
  run-hook-wrapped(#f(compiled-function (fun) #<bytecode 0x58b8eea09c11c75>) valign-region)
  jit-lock--run-functions(1 501)
  jit-lock-fontify-now(1 501)
  jit-lock-function(1)
  redisplay_internal\ \(C\ function\)()

这个 #+begin_example 里的 | 会被识别为表格的开头,应该不对这块区域内做处理?

今天更新valign,发现已经支持缩进,真的太棒了。
终于可以任意选择字体了。 :+1: 感谢 @casouri
大佬什么时候回归啊,我们需要你 :grinning:

牛逼啊哥们。

@casouri 现在长期在 telegram 频道 :slight_smile:

太好用了,手动点赞

楼主,你的这个包可以支持 elfeed 不? elfeed 有中文标题的时候,就很容易对不齐.

1 个赞

可以重写 elfeed-search-print-entry-function, 用

    (valign--put-overlay beg end 'display (valign--space align-to-pixel))

来对齐.

我的写法, 供参考…

  (defun elfeed-search-print-valigned-entry (entry)
    "Print valign-ed ENTRY to the buffer."
    (let* ((date (elfeed-search-format-date (elfeed-entry-date entry)))
	   (date-width (car (cdr elfeed-search-date-format)))
           (title (or (elfeed-meta entry :title) (elfeed-entry-title entry) ""))
           (title-faces (elfeed-search--faces (elfeed-entry-tags entry)))
           (feed (elfeed-entry-feed entry))
           (feed-title
            (when feed
              (or (elfeed-meta feed :title) (elfeed-feed-title feed))))
           (tags (mapcar #'symbol-name (elfeed-entry-tags entry)))
           (tags-str (mapconcat
                      (lambda (s) (propertize s 'face 'elfeed-search-tag-face))
                      tags ","))
           (title-width (- (window-width) 10 elfeed-search-trailing-width))
           (title-column (elfeed-format-column
                          title (elfeed-clamp
				 elfeed-search-title-min-width
				 title-width
				 elfeed-search-title-max-width)
                          :left))
	   (align-to (* (+ date-width 2 (max elfeed-search-title-min-width 
                                         (min title-width elfeed-search-title-max-width)))
			(default-font-width))))
      (insert (propertize date 'face 'elfeed-search-date-face) " ")
      (insert (propertize title-column 'face title-faces 'kbd-help title) " ")
      (valign--put-overlay (1- (point)) (point) 'display (valign--space align-to))
      (when feed-title
	(insert (propertize feed-title 'face 'elfeed-search-feed-face) " "))
      (when tags
	(insert "(" tags-str ")"))))

  (setq elfeed-search-print-entry-function #'elfeed-search-print-valigned-entry)
3 个赞

哈哈哈,我刚刚也是发现这个方法,已经给elfeed的作者发补丁了 Use property align-to indent title pixel width by manateelazycat · Pull Request #404 · skeeto/elfeed · GitHub

对齐之前的效果 https://ibb.co/RDzxScK

补丁后的效果 https://ibb.co/pJz4z74

6 个赞

如果能合到 elfeed 就太好了.

关于 PR, 我觉得这里的 title-width 需要换成 (+ date-width 2 (min title-width elfeed-search-title-max-width). 如果 (window-width) 比较小, aligned-to 会挤到标题里面去.

    (elfeed-indent-pixel (* title-width (window-font-width))))

我这个还对不齐 ** 惯导性能 | performance | Gyroscope | Accelerometer | |------------------±----------------±--------------| | Full-scale Range | ±2000 °/s | ±16 g | | Bias stability | 10 °/h | 30 µg | | Noise density | 0.007 °/s/√Hz | 120 µg/√Hz | | Non-linearity | 0.1% FS | 0.5% FS |

把 ± 换成 +, 我这里就可以了:

image

1 个赞

我还有另一个问题下面的表格emacs只开一个窗口显示是正常的,开多个窗口后,显示就不正常了.

| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | |------±---------±-------------±---------±-----±----±-------±------------±----------±------------±--------------±--------±------------±-------| | UID | USB_VBUS | ETH_LINK_ACT | ETH_BIAS | NC | 3V3 | USB_D- | USB_D+/RXD3 | nRESET_IN | VARF/CAN1RX | EVENT2/CAN1TX | CAN2RX | EVENT1/TXD3 | GND | |------±---------±-------------±---------±-----±----±-------±------------±----------±------------±--------------±--------±------------±-------| | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | |------±---------±-------------±---------±-----±----±-------±------------±----------±------------±--------------±--------±------------±-------| | TXD1 | RXD1 | GND | TXD2 | RXD2 | GND | PV | GND | PPS | CAN2TX | ETH_TD+ | ETH_RD+ | ETH_TD- | ETHRD- |

会不会是你的表格太长了? :grinning:

应该是你的表格太长了。此处安利同一个作者的另一个包 GitHub - casouri/ftable: Fill (auto-layout) tables

2 个赞

这样好算一点,如果要挤到标题里面去,证明窗口太小了,哈哈哈哈。

看我PR里面的最新补丁吧。

如果窗口足够大,我用的是 title-width, 如果窗口不够大,比如只有一半就换一个更小的值。

1 个赞