简体   繁体   English

如何让 Emacs 的 ELPA list-packages 的“package”栏更宽?

[英]How to make the “package” column of Emacs' ELPA list-packages screen wider?

When I run list-packages on Emacs 24, I get a screen that looks like the following:当我在 Emacs 24 上运行list-packages时,我看到如下所示的屏幕:

埃尔帕

The problem is that many packages' names are longer than the package column.问题是许多包的名称都比包列长。 How do I make this column wider so that I can see the full package names?如何使此列更宽,以便我可以看到完整的包名称?

Maybe there is a more elegant solution but I came up with this.也许有一个更优雅的解决方案,但我想出了这个。 You can define the width of the column using following code and changing the variable package-menu-column-width to your needs.您可以使用以下代码定义列的宽度,并根据需要更改变量package-menu-column-width Then, you need to include it to your init file (after (require 'package) ).然后,您需要将它包含到您的 init 文件中(在(require 'package) )。 It is from the package.el file which defines the format of the table.它来自定义表格格式的package.el文件。 See the first comment inside the code where you need to modify the width of the column.请参阅代码中需要修改列宽的第一条注释。 You can proceed in a similar way for the other columns.您可以以类似的方式处理其他列。

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

The http://www.github.com/purcell/emacs.d repository includes the following in the lisp/init-elpa.el setup file which looks like it would address your problem. 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)

I do know this is an old question, but I hope my answer may be useful.... (btw I've checked it with emacs 26.1 and package manager 1.1.0 running on Windows 8.1)我确实知道这是一个老问题,但我希望我的回答可能有用....(顺便说一句,我已经使用在 Windows 8.1 上运行的 emacs 26.1 和包管理器 1.1.0 对其进行了检查)

let's find 'package.el' file - in my system it's in folder:让我们找到“package.el”文件 - 在我的系统中,它位于文件夹中:

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

open it in your emacs ... find a piece of code looking like this one: (in my system these are lines 2553..2559 of 'package.el' file)在你的 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)])                                 

As You can see here are the package manager columns width definitions.如您所见,这里是包管理器列宽定义。 Change the width of the appropriate column(s) according to your needs ... (in my case 18 -> 25, 13 -> 15, 10 -> 10, 13 -> 15 was enough).根据您的需要更改适当列的宽度......(在我的情况下,18 -> 25, 13 -> 15, 10 -> 10, 13 -> 15 就足够了)。

'byte-compile' this file (eg pick this option in 'Emacs-Lisp' menu) you should receive the message: 'byte-compile' 这个文件(例如在 'Emacs-Lisp' 菜单中选择这个选项)你应该收到消息:

"Wrote \\package.elc" “写\\package.elc”

restart Emacs重启 Emacs

Voila!瞧!

PS: Of course this is not elegant and only temporary solution; PS:当然这不是优雅的,只是暂时的解决方案; It works until next Emacs update only (of course you can repeat this procedure after emacs update...)它只工作到下一次 Emacs 更新(当然你可以在 emacs 更新后重复这个过程......)

The answer by Tim X above is the closest to what I think is what is wanted - however the function there calculates the length of the largest item in the "Archive" column before setting the relevant column width.上面Tim X的答案最接近我认为想要的东西 - 但是那里的函数在设置相关列宽度之前计算“存档”列中最大项目的长度。 In order to achieve the "Package" column being sized to the largest item in it, I found the below worked for me:为了实现“包”列的大小调整为其中最大的项目,我发现以下内容对我有用:

(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)

Here's my take on this.这是我对此的看法。 It adds a package-menu-mode hook (like the purcell solution) and modifies tabulated-list-format in a more concise fashion than the other solutions.它添加了一个package-menu-mode挂钩(如 purcell 解决方案)并以比其他解决方案更简洁的方式修改tabulated-list-format It also widens the "Archive" column because I hated seeing melpa-s... instead of melpa-stable .它还扩大了“存档”列,因为我讨厌看到melpa-s...而不是melpa-stable (Yes, the column had the ellipsis.) I didn't bother with some function that calculates the column width on the fly because it's not going to change often and almost every package name is going to be less than or equal to it. (是的,该列有省略号。)我没有打扰一些动态计算列宽的函数,因为它不会经常更改,并且几乎每个包名称都将小于或等于它。

(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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM