Automatically insert member functions (Emacs extension) in C ++

xiaoxiao2021-03-05  19

I spent a few days a few days, I saw the ELISP language, the brackets saw dizzy, and I couldn't write an ELISP extension. Now I feel that the simple LISP is not so painful.

Usage: You can place the cursor in the current function row in the C header file, and then press C-C I to insert member functions in the corresponding source file.

Supports multi-layer Namespace and Class. However, it is not very reliable, such as support for the default parameter value.

(Defun cpp-current-scope ()

"If the point is in a class / namespace / struct definition, gets the

Full Scope path. Return nil Otherwise. "

(Interactive)

(let (syntax-list scope))

(Save-ExcURSION

;; Ensure We aren't in the arguments list

Beginning-of-line

(c-end-of-statement)

(c-beginning-of-statement-1)

; Now point is at beginningning of the funciton declaration,

;; Call C-guest-Basic-syntax to find if the car is inclass or innamespace

(SetQ Syntax-List (C-Guess-Basic-Syntax))

;; expected format '(INCLASS 12) | (Innamespace 22) ...))

(While (OR (EQ 'Inclass (Car Syntax-List)))

(EQ 'Innamespace (Car Syntax-List)))))))))))))))))

; Find Outside The Class / Namespace Name

(Goto-char (ELT (Car Syntax-List) 1))

(Backward-Word)

(SetQ ClassNames (consisting) ClassNames)

;; while loop, check outside scope again

(SetQ Syntax-List (C-Guess-Basic-Syntax))))))

;; Concat The Scope List Like NS1 :: ns2 :: Class1 ::

(DOLIST (E classnames scpe)

(SetQ Scope (Concat Scope E "::"))))))))))))))))))

(Defun cpp-current-function ()

"Check Current Line Functon Declaration, Return A List, The 0th is The THE

Rettype, 1st is Function Name,

2th Is The Arg List, 3th Is Modifier

Such as' ('Void' 'Foo' 'Int A, INT B' 'CONST') "

(Interactive)

(Save-ExcURSION

(LET (String List Rettype Func Argument (MODIFIER ")

START END)

Beginning-of-line

(Setq End (PRONT)) (POINT)))

(SetQ Start (PROINT)) (WHEN (Search-Forward "(" End T)

(setq string (buffer-substring-no-proties start (1- (point)))))))

(SetQ Start (Point))

(when (Search-Forward ")" END T)

(setq argument (buffer-substring-no-proties start (1- (point)))))))))))

(setq modifier (buffer-substring-no-protiet (1- end))))

(SetQ List (split-string string))

(SetQ Func (ELT LIST (1- (Length List)))))))

(if (> (> length lis) 2)

(SetQ Rettype (ELT LIST 1))

(if (= (Length List) 1)

; No Rettype, Construction Or Destruction

(setq rettype "")

(SetQ Rettype (Car List))))))))))))

(SetQ List (List Rettype Func Argument Modifier)))))))))))))))))

(Defun CPP-INSERT-new -Method ()

"INSERT A C MEMBER FUNCTION DEFINITION INTO The Corresponding C Source File.

Try to Find the Definition IF EXISTS

(Interactive)

(LET (insertstr (CLASSNAME (CPP-Current-Scope))

(phototype (cpp-current-function))))))))

(if (or (null phototype)) (NULL CLASSNAME))

(Message "Cann't Insert CPP MEMBER FUNCTION!")

(FF-FIND-RELATED-FILE)

(setq insertstr

(ELT phototype 0)

(unless) "" "" "" "

Classname

(ELT phototype 1) "(" (ELT phototype 2) ")")

(ELT phototype 3))))))))))

Beginning-of-buffer

(unless-forward insertstr (point-max) t)

(End-of-buffer)

(INSERT "/ N / N")

(End-of-buffer)

(INSERT INSERTSTR)

(INSERT "/ n {/ n")

(c-indent-defun)

(INSERT "} / n")

(Backward-char 3)

(INSERT "/ N")

(c-indent-line-or-region))))))))))))))))

(GLOBAL-SET-key "/ c-ci" 'cpp-insert-new-method)

转载请注明原文地址:https://www.9cbs.com/read-38673.html

New Post(0)