如何使 emacs 中的自动完成功能匹配长 perl 变量?

发布于 2024-11-05 19:53:04 字数 181 浏览 0 评论 0原文

自动完成功能最好的功能就是匹配单词字符。例如:自动完成将仅匹配先前使用的变量 $longvariablename[$i]{'key'} 中的 $longvariablename。我想配置自动完成或任何其他 emacs el 文件以匹配整个变量。

作为最后的手段,我必须学习 lisp #shudder#。

提前致谢。

The best auto-complete can do is match word characters. For example: auto-complete will only match $longvariablename in a previously used variable, $longvariablename[$i]{'key'}. I would like to configure auto-complete, or any other emacs el file to match the entire variable.

As a last resort, I'm going to have to learn lisp #shudder#.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

客…行舟 2024-11-12 19:53:04

您可以自定义嬉皮扩展

例如,以下自定义将所有字符串展开直到出现空格或分号。

(defun try-expand-perl-extended-var (old)
  (let ((old-fun (symbol-function 'he-dabbrev-search)))
    (fset 'he-dabbrev-search (symbol-function 'perl-extended-var-search))
    (unwind-protect
        (try-expand-dabbrev old)
      (fset 'he-dabbrev-search old-fun))))


(defun perl-extended-var-search (pattern &optional reverse limit)
  (let ((result ())
    (regpat (concat (regexp-quote pattern) "[^ ;]+")))
    (while (and (not result)
        (if reverse
             (re-search-backward regpat limit t)
             (re-search-forward regpat limit t)))
      (setq result (buffer-substring-no-properties (save-excursion
                                                     (goto-char (match-beginning 0))
                                                     (skip-syntax-backward "w_")
                                                     (point))
                           (match-end 0)))
      (if (he-string-member result he-tried-table t)
      (setq result nil)))     ; ignore if bad prefix or already in table
    result))

不要忘记将您的自定义函数包含到 make-hippie-expand-function 列表中

(global-set-key [(meta f5)] (make-hippie-expand-function
                               '(try-expand-perl-extended-var
                                 try-expand-dabbrev-visible
                                 try-expand-dabbrev
                                 try-expand-dabbrev-all-buffers) t))

You can customize hippie expand.

For example the following customization expands all strings until a space or a semicolon.

(defun try-expand-perl-extended-var (old)
  (let ((old-fun (symbol-function 'he-dabbrev-search)))
    (fset 'he-dabbrev-search (symbol-function 'perl-extended-var-search))
    (unwind-protect
        (try-expand-dabbrev old)
      (fset 'he-dabbrev-search old-fun))))


(defun perl-extended-var-search (pattern &optional reverse limit)
  (let ((result ())
    (regpat (concat (regexp-quote pattern) "[^ ;]+")))
    (while (and (not result)
        (if reverse
             (re-search-backward regpat limit t)
             (re-search-forward regpat limit t)))
      (setq result (buffer-substring-no-properties (save-excursion
                                                     (goto-char (match-beginning 0))
                                                     (skip-syntax-backward "w_")
                                                     (point))
                           (match-end 0)))
      (if (he-string-member result he-tried-table t)
      (setq result nil)))     ; ignore if bad prefix or already in table
    result))

Don't forget to include your custom function into make-hippie-expand-function list

(global-set-key [(meta f5)] (make-hippie-expand-function
                               '(try-expand-perl-extended-var
                                 try-expand-dabbrev-visible
                                 try-expand-dabbrev
                                 try-expand-dabbrev-all-buffers) t))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文