简体   繁体   English

如何在Emacs VHDL模式下对齐某些文本

[英]How to align certain text in emacs vhdl-mode

In Emacs how would I align a group of text: 在Emacs中,我如何对齐一组文本:

signal slv4   : std_logic_vector(3 downto 0);
signal slv16  : std_logic_vector(15 downto 0);
signal slv8   : std_logic_vector(7 downto 0);
signal slv32  : std_logic_vector(32 downto 0);

so it looks like this 所以看起来像这样

signal slv4   : std_logic_vector( 3 downto 0);
signal slv16  : std_logic_vector(15 downto 0);
signal slv8   : std_logic_vector( 7 downto 0);
signal slv32  : std_logic_vector(32 downto 0);

Basically I want to right justify the numbers before "downto"; 基本上,我想右对齐数字,直到“ downto”; another side effect is that the text is right justified (the semi-colons line up). 另一个副作用是文本右对齐(分号排列)。

How would I achieve this? 我将如何实现? I have played around with Mx align and Mx align-regexp however I can't seem to get what I'm looking for. 我玩过Mx alignMx align-regexp但是我似乎无法获得想要的东西。

Also I'm using vhdl-mode so maybe it has something built in? 另外我正在使用vhdl-mode,所以也许它内置了某些内容?

I don't think there is such a thing in vhdl mode because you need spaces in the middle of the text. 我认为在vhdl模式下不会出现这种情况,因为在文本中间需要空格。 If it were just about right aligning, you could possibly play around with tab behaviour. 如果只是正确对齐,则可以尝试使用tab行为。 In this case, you could use a macro. 在这种情况下,您可以使用宏。

http://www.emacswiki.org/emacs/KeyboardMacros http://www.emacswiki.org/emacs/KeyboardMacros

In a first run the maximum of padding is detected, than called recursively with padding given. 在第一次运行中,检测到最大的填充,然后在给定填充的情况下递归调用。

Edit `this-regexp' inside let if something different is needed. 如果需要其他内容,请在let中编辑`this-regexp'。 Maybe the hard-coded opening "(" in concat-form needs edit than too. 可能以concat形式的硬编码开头“(”需要编辑。

(defun my-numbers-padded (&optional beg end len)
  "Pad numbers as given in example string "
  (interactive "*")
  (let* ((beg (cond (beg)
                    ((use-region-p)
                     (region-beginning))
                    (t (point-min))))
         (end (cond (end (copy-marker end))
                    ((use-region-p)
                     (copy-marker (region-end)))
                    (t (copy-marker (point-max)))))
         (this-regexp "^\\([^(]+\\)\(\\([0-9]+\\)\\(.+\\)$")
         (len len)
         lenmax
         (var (and len (concat "(format \"%" (number-to-string len) "s\" (match-string-no-properties 2))"))))
    (goto-char beg)
    (if len
        (while (re-search-forward this-regexp  nil t 1)
          (setq erg (eval (car (read-from-string var))))
          (replace-match
           (concat (match-string-no-properties 1) "\("   erg (match-string-no-properties 3))))
      (while (re-search-forward this-regexp  nil t 1)
        (setq current-length (length (match-string-no-properties 2)))
        (if (and lenmax (< lenmax current-length))
            (setq lenmax current-length)
          (unless lenmax (setq lenmax current-length))))
      (my-padding-numbers beg end lenmax))))

Here is what I'm currently using (which works fine): 这是我当前正在使用的(效果很好):

(defun my-align-downto (beg end)
    (interactive "r")
    (align-regexp beg end "\\([0-9]* downto*\\)" -1 0 t))

I thought I would take it one step further and create my own 'align hook' based on the information at the very bottom of this page: http://www.emacswiki.org/emacs/AlignCommands#toc8 我以为我会更进一步,并根据此页面底部的信息创建自己的“对齐钩子”: http : //www.emacswiki.org/emacs/AlignCommands#toc8

(add-hook 'align-load-hook (lambda ()
    (add-to-list 'align-rules-list
      '(downto-align
        (regexp  . "\\([0-9]* downto*\\)")
        (group   . -1)
        (spacing . 0)
        (modes   . vhdl-mode)
        (repeat  . t)))))

With which I get no results. 我没有结果。 :( :(

Does vhdl-mode override these alignment rules.. or am I just not doing something correctly? vhdl-mode是否会覆盖这些对齐规则..还是我只是做错了什么?

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

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