8

当我list-packages在 Emacs 24 上运行时,我得到一个如下所示的屏幕:

埃尔帕

问题是许多包的名称比包列长。如何使此列更宽以便我可以看到完整的包名称?

4

5 回答 5

3

也许有一个更优雅的解决方案,但我想出了这个。您可以使用以下代码定义列的宽度并将变量更改package-menu-column-width为您的需要。然后,您需要将它包含到您的 init 文件中(在 之后(require 'package))。它来自package.el定义表格格式的文件。请参阅代码中需要修改列宽的第一条注释。您可以以类似的方式处理其他列。

;; <<<< here you have to adapt the number to your needs >>>>
(defcustom package-menu-column-width 18
  "Width of the package column."
  :type 'number
  :group 'package)

(define-derived-mode package-menu-mode tabulated-list-mode "Package Menu"
  "Major mode for browsing a list of packages.
Letters do not insert themselves; instead, they are commands.
\\<package-menu-mode-map>
\\{package-menu-mode-map}"
  (setq tabulated-list-format
        `[("Package" ,package-menu-column-width package-menu--name-predicate)
          ("Version" 12 nil)
          ("Status"  10 package-menu--status-predicate)
          ,@(if (cdr package-archives)
                '(("Archive" 10 package-menu--archive-predicate)))
          ("Description" 0 nil)])
  (setq tabulated-list-padding 2)
  (setq tabulated-list-sort-key (cons "Status" nil))
  (add-hook 'tabulated-list-revert-hook 'package-menu--refresh nil t)
  (tabulated-list-init-header))
于 2015-02-07T20:26:54.593 回答
0

http://www.github.com/purcell/emacs.d存储库在lisp/init-elpa.el 设置文件中包含以下内容,看起来可以解决您的问题。

(require-package 'cl-lib)
(require 'cl-lib)

(defun sanityinc/set-tabulated-list-column-width (col-name width)
  "Set any column with name COL-NAME to the given WIDTH."
  (cl-loop for column across tabulated-list-format
           when (string= col-name (car column))
           do (setf (elt column 1) width)))

(defun sanityinc/maybe-widen-package-menu-columns ()
  "Widen some columns of the package menu table to avoid truncation."
  (when (boundp 'tabulated-list-format)
    (sanityinc/set-tabulated-list-column-width "Version" 13)
    (let ((longest-archive-name (apply 'max (mapcar 'length (mapcar 'car package-archives)))))
      (sanityinc/set-tabulated-list-column-width "Archive" longest-archive-name))))

(add-hook 'package-menu-mode-hook 'sanityinc/maybe-widen-package-menu-columns)
于 2015-02-12T21:27:20.710 回答
0

这是我对此的看法。它添加了一个package-menu-mode钩子(如 purcell 解决方案)并tabulated-list-format以比其他解决方案更简洁的方式进行修改。它还扩大了“存档”列,因为我讨厌看到melpa-s...而不是melpa-stable. (是的,该列有省略号。)我没有打扰一些即时计算列宽的函数,因为它不会经常更改,并且几乎每个包名称都将小于或等于它。

(defcustom dse/package-menu/package-column-width 32
  "Column width of package name in list-packages menu."
  :type 'number :group 'package)
(defcustom dse/package-menu/archive-column-width 12
  "Column width of archive name in list-packages menu."
  :type 'number :group 'package)
(defun dse/package-menu/fix-column-widths ()
  (let ((tlf (append tabulated-list-format nil)))
    (setf (cadr (assoc "Package" tlf)) dse/package-menu/package-column-width)
    (setf (cadr (assoc "Archive" tlf)) dse/package-menu/archive-column-width)
    (setq tabulated-list-format (vconcat tlf))))

(add-hook 'package-menu-mode-hook #'dse/package-menu/fix-column-widths)
于 2019-10-26T06:35:53.253 回答
0

上面Tim X的答案最接近我认为想要的结果 - 但是那里的函数在设置相关列宽之前计算“存档”列中最大项目的长度。为了实现“包”列的大小调整为其中最大的项目,我发现以下内容对我有用:

(require 'cl-lib)
(defun godeater/set-tabulated-list-column-width (col-name width)
  "Set any column with the name COL-NAME to the given WIDTH."
  (cl-loop for column across tabulated-list-format
       when (string= col-name (car column))
       do (setf (elt column 1) width)))

(defun godeater/maybe-widen-package-menu-columns ()
  "Widen some columns of the package menu table to avoid truncation."
  (when (boundp 'tabulated-list-format)
    (godeater/set-tabulated-list-column-width "Version" 13 )
    (let ((longest-package-name (apply 'max (mapcar 'length (mapcar 'symbol-name (mapcar 'car package-archive-contents))))))
      (godeater/set-tabulated-list-column-width "Package" longest-package-name))))

(add-hook 'package-menu-mode-hook 'godeater/maybe-widen-package-menu-columns)
于 2018-12-14T20:50:31.913 回答
0

我知道这是一个老问题,但我希望我的回答可能有用....(顺便说一句,我已经用在 Windows 8.1 上运行的 emacs 26.1 和包管理器 1.1.0 进行了检查)

让我们找到“package.el”文件 - 在我的系统中,它位于文件夹中:

d:\Program Files2\emacs\share\emacs\26.1\lisp\emacs-lisp\

在你的 emacs 中打开它......找到一段看起来像这样的代码:(在我的系统中,这些是 'package.el' 文件的第 2553..2559 行)

(setq tabulated-list-format
    `[("Package" 18 package-menu--name-predicate)
      ("Version" 13 nil)
      ("Status"  10 package-menu--status-predicate)
      ,@(if (cdr package-archives)
            '(("Archive" 13 package-menu--archive-predicate)))
      ("Description" 0 nil)])                                 

如您所见,这里是包管理器列的宽度定义。根据您的需要更改相应列的宽度......(在我的情况下 18 -> 25, 13 -> 15, 10 -> 10, 13 -> 15 就足够了)。

'byte-compile' 这个文件(例如在 'Emacs-Lisp' 菜单中选择这个选项)你应该会收到消息:

“写了\package.elc”

重启 Emacs

瞧!

PS:当然这不是优雅的,只是暂时的解决方案;它仅在下一次 Emacs 更新之前有效(当然您可以在 emacs 更新后重复此过程...)

于 2018-07-19T17:04:42.593 回答