Emacs 我无法在自动完成或工具提示中获取结构成员

Emacs 我无法在自动完成或工具提示中获取结构成员,emacs,autocomplete,elisp,emacs24,Emacs,Autocomplete,Elisp,Emacs24,我希望autocomplete或company使用C代码,我需要结构上下文级别的autocomplete,即如果我有一个结构: typefdef struct HOST_ { IP4_ADDRESS ip4; IP6_ADDRESS ip6; MAC_ADDRESS mac; } HOST; 。。。然后我有代码: HOST host; host-> 然后,如果我点击tab键,我会得到一个下拉菜单,提供所有(并且只有)三个选项

我希望autocomplete或company使用C代码,我需要结构上下文级别的autocomplete,即如果我有一个结构:

typefdef struct HOST_ {

    IP4_ADDRESS     ip4;
    IP6_ADDRESS     ip6;
    MAC_ADDRESS     mac;    
} HOST;
。。。然后我有代码:

HOST host;

host->
然后,如果我点击tab键,我会得到一个下拉菜单,提供所有(并且只有)三个选项

这就是我所做的:

(defun my-tab-del-commands(key-map)
  "This function sets the <tab> and <backspace> keymaps according to the special commands
that I have set. This needs to be set per mode keymap where it is needed. We cannot 
use the global keymap because that would override command completion in minibuffer"

  ;; Set TAB in  major-mode keymap to "tab-to-tab" stop
  ;; Use tab2tab stop and not just add +4 spaces (tab stop defined by tag-stop-list)
  (define-key key-map (kbd "<tab>")     'tab-to-tab-stop)

  ;; Define Key for <backtab>
  (define-key key-map (kbd "<S-tab>")   'backward-move-to-tab-stop)
  (define-key key-map (kbd "<backtab>") 'backward-move-to-tab-stop)

  ;; Define C-tab as my-indent-system 
  (define-key key-map (kbd "<C-tab>")   'my-indent-system)
  ;; Also provide a duplicate "\C-ci" in case C-TAB is overridden by any minor mode
  (define-key emacs-lisp-mode-map "\C-ci"   'my-indent-system)

  ;; Shift backspace moves by one tab stop till no more whitespace
  (define-key key-map (kbd "<S-backspace>") 'backspace-whitespace-to-tab-stop)

  ;; Alt backspace is c-hungry-delete-backwards
  (define-key key-map (kbd "<M-backspace>") 'c-hungry-delete-backwards)
  )


;; Simple Backend of semantic with ede as project manager
;; Lets try semantic (CDET) backend for now only.
;; Later learn clang or rtags or other big stuff to handle the whole project
(defun backend:semantic-ede ()
  "Setup for semantic-mode with ede as project management. 
Simple stuff for starters"

  (semantic-mode 1)

  (global-semanticdb-minor-mode 1)
  (global-semantic-idle-scheduler-mode 1)
  (setq-mode-local c-mode semanticdb-find-default-throttle
                   '(project unloaded system recursive))
  (semantic-add-system-include my-lp-build-path)
  (semanticdb-enable-gnu-global-databases 'c-mode t)
  (semanticdb-enable-gnu-global-databases 'c++-mode t)

  (require 'ede)
  (global-ede-mode)

  (let ((makefile (format "%s/Makefile" my-mp-source-path)))
    (when (file-exists-p makefile)
      (ede-cpp-root-project "openflow" :file makefile)))
  )


;; There are two "schools of thought" of intelligent autocomplete
;; (a) auto-complete package and (b) company package. 


;; This is auto-complete
(defun completion:auto-complete ()
  "Setup auto-complete with triggers. We still need to hook with C mode"

  ;; Then autocomplete
  (require 'auto-complete)
  (require 'auto-complete-config)
  (global-auto-complete-mode t)

  ;; auto complete mod
  ;; should be loaded after yasnippet so that they can work together

  (add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
  (ac-config-default)

  (add-hook 'auto-complete-mode-hook 'ac-common-setup)

  ;; set the trigger key so that it can work together with yasnippet on tab key,
  ;; if the word exists in yasnippet, pressing tab will cause yasnippet to
  ;; activate, otherwise, auto-complete will
  (ac-set-trigger-key "TAB")
  (ac-set-trigger-key "<tab>")  
  (global-auto-complete-mode t)

)

(defun my-smart-c-auto-complete()
  ;; Now tie up autocomplete with semantic
  ;; Later hook it up to c-mode-hook via c-mode-config func
  (require 'auto-complete-c-headers)
  (add-to-list 'ac-sources 'ac-source-words-in-same-mode-buffers)
  (add-to-list 'ac-sources 'ac-source-dictionary)
  (add-to-list 'ac-sources 'ac-source-abbrev)

  (add-to-list 'ac-sources 'ac-source-semantic)
  (add-to-list 'ac-sources 'ac-source-c-headers)
)


;; This is company
(defun completion:company ()
    "Setup comany mode"
    (require 'company)
    (add-hook 'after-init-hook 'global-company-mode)
)

(defun tab-side-story ()
  (interactive)

  ;; First load and init Yasnippet - This sets the TAB first to Ysnippet
  ;; This will work on LISP & SHELL SCRIPTS also

  ;; (require 'yasnippet)
  ;; (yas-global-mode 1)

  ;; Second, use whatever completion mechanism you wanna use auto-complete or company
  ;; This will work on LISP also!
  ;;(completion:auto-complete)
  (completion:company)

  ;; Then this function sets tab command 
  (my-tab-del-commands c-mode-base-map)

)

;; Completion mechanism needs a backend
(backend:semantic-ede)
(tab-side-story)

;; define My Great C style with linux as the parent style (choose google if you wish)
(c-add-style "my-great-c-style"
             '("linux"              ; use linux as parent style
               (indent-tabs-mode . nil)     ; tabs are spaces
               (c-syntactic-indentation . t)    ; auto-syntax
               (c-syntactic-indentation-in-macros . t) ; ditto for macros
               (c-tab-always-indent . nil) ; Otherwise our complex TAB will not work!
               (tab-width   .  4)           ; if there is a <tab> expand to 4 spaces
               (backward-delete-function . nil)     ; DO NOT expand tabs when deleting
               (c-continued-statement-offset . 4))) ;continued statement offset 4


(defun my-c-mode-config ()
  (c-set-style "my-great-c-style")
  (when (= emacs-major-version 23)
    (gtags-mode 1))
   (when (= emacs-major-version 24)
    (tab-side-story)
    ;; (my-smart-c-auto-complete)
    (ggtags-mode 1)
    (setq ggtags-update-on-save nil))
  (electric-indent-mode)
  (setq c-basic-offset   4)
  (setq c-tab-always-indent nil))

;; Needs to be hooked - do it here instead of common area 
(add-hook 'c-mode-hook 'my-c-mode-config)           
(取消我的制表符删除命令(键映射)
“此功能根据特殊命令设置和键映射
我已经设置了。这需要根据需要的模式键映射进行设置。我们不能
使用全局键映射,因为这将覆盖minibuffer中的命令完成”
;将主模式下的TAB键映射设置为“TAB to TAB”停止
;;使用tab2tab-stop,而不仅仅是添加+4个空格(tab-stop由tag-stop列表定义)
(定义键-键映射(kbd“”)“制表位到制表位)
定义键
(定义键映射(kbd“”)'向后移动到制表位)
(定义键映射(kbd“”)'向后移动到制表位)
;将C-tab定义为我的缩进系统
(定义键映射(kbd“”)“我的缩进系统”)
;如果C-TAB被任何次要模式覆盖,还应提供一个重复的“\C-ci”
(定义键emacs lisp模式映射“\C-ci”我的缩进系统)
;Shift退格键移动一个制表位,直到不再有空格
(定义键映射(kbd“”)“将空格返回到制表位”
;Alt backspace是c-Hurn-delete-backwards
(定义键映射(kbd“”)'c-hungry-delete-backwards)
)
;; 简单的语义后端,由ede担任项目经理
;; 现在让我们尝试语义(CDET)后端。
;; 稍后学习clang或RTag或其他大的东西来处理整个项目
(defun后端:语义ede()
“使用ede作为项目管理设置语义模式。
“简单的入门材料”
(语义模式1)
(全局语义CDB次要模式1)
(全局语义空闲计划程序模式1)
(setq模式本地c模式语义CDB查找默认油门
'(项目卸载系统递归)
(语义添加系统包括我的lp构建路径)
(semanticdb启用gnu全局数据库的c模式t)
(semanticdb启用gnu全局数据库的c++模式t)
(需要“ede”)
(全局ede模式)
(let((makefile(格式“%s/makefile”我的mp源路径)))
(当(file-exists-p makefile)
(ede cpp根项目“openflow”:文件makefile)))
)
;; 智能自动完成有两个“思想流派”
;; (a) 自动完成包装和(b)公司包装。
;; 这是自动完成的
(卸载完成:自动完成()
“使用触发器自动完成安装。我们仍然需要使用C模式挂接”
然后自动完成
(需要“自动完成”)
(需要“自动完成配置”)
(全局自动完成模式t)
自动完成模式
应在yasnippet之后加载,以便它们可以一起工作
(添加到列表“ac字典目录”~/.emacs.d/ac dict”)
(ac配置默认值)
(添加挂钩“自动完成模式挂钩”ac公共设置)
;设置触发键,使其可以与tab键上的yasnippet一起工作,
;如果单词存在于yasnippet中,则按tab键将导致yasnippet
;激活,否则将自动完成
(交流设置触发键“TAB”)
(ac设置触发键“”)
(全局自动完成模式t)
)
(定义my-smart-c-auto-complete()
现在将自动完成与语义
;稍后通过c-mode-config func将其连接到c-mode-hook
(需要“自动完成-c-标题”)
(添加到相同模式缓冲区中的“交流电源”交流电源字列表中)
(添加到列表“交流电源”交流电源字典)
(添加到列表“交流电源”交流电源缩写)
(添加到“交流电源”列表交流电源语义)
(添加到列表“交流电源”ac-source-c-HEADER)
)
;; 这是我的公司
(完成日期:公司()
“设置comany模式”
(要求“公司”)
(在全局公司模式下,在初始钩子后添加钩子)
)
(defun选项卡侧楼层()
(互动)
;;首次加载并初始化Yasnippet-这将首先将选项卡设置为Ysnippet
;这也适用于LISP和SHELL脚本
59426
(yas全局模式1)
第二,使用任何你想使用的自动完成或公司完成机制
这也适用于LISP!
;(完成:自动完成)
(完成日期:公司)
;然后此函数设置tab命令
(我的选项卡del命令c-mode-base-map)
)
;; 完成机制需要一个后端
(后端:语义ede)
(附页)
;; 用linux作为父样式定义我伟大的C样式(如果愿意,选择google)
(c-add-style“my-great-c-style”
“(“linux”)使用linux作为父样式
(缩进制表符模式.nil);制表符是空格
(c-syntarchy-indentation.t);自动语法
(c-syntarchy-indentation-in-macros.t);宏也是如此
(c-tab-always-indent.nil);否则我们的复杂选项卡将无法工作!
(制表符宽度4);如果有扩展到4个空格
(向后删除函数.nil);删除时不展开选项卡
(c-续-statement-offset.4);续报表抵销4
(定义my-c-mode-config()
(c-set-style“my-great-c-style”)
(当(=emacs主要版本23)
(gtags模式1))
(当(=emacs主版本24)
(附页)
(my-smart-c-auto-complete)
(模式1)
(setq ggtags在保存nil时更新)
(电子缩进模式)
(setq c-基本-偏移量4)
(setq c-tab-always-indent nil)
;; 需要上钩-在这里上钩,而不是在公共区域
(添加钩子'c-mode-hook'my-c-mode-config)
很抱歉,代码太长了,但大多数都是我的评论和笔记,我记下的“代码”比看起来要少得多。在这个我已经设置为公司模式,虽然我有自动完成


两个都不行!某物与某物碰撞

你能在你的编程中运行javascript吗?不能。主要是C、ELISP、EXPECT,有时还有BASH和PERL