Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defvar emr-c:--semantic-tag-list '()
- "[INTERNAL] List of semantic tags in current buffer.")
- (defcustom emr-c-implementation-extensions
- '("c" "cpp")
- "Specify extensions that indicate current file is an implementation files."
- :group 'emr)
- (defun emr-c:--semantic-fetch-candidates ()
- (setq emr-c:--semantic-tag-list nil)
- (emr-c:--semantic-fetch-candidates-helper (semantic-fetch-tags) 0 nil))
- (defun emr-c:--semantic-fetch-candidates-helper (tags depth &optional class)
- "Return a list of pairs '(DISPLAY . REAL), where DISPLAY is the string to be
- presented to user, while REAL is a semantic tag.
- TAGS are collection of Semantic tags in current buffer.
- DEPTH is current recursion depth.
- CLASS is the parent class."
- (let ((spaces (make-string (* depth 2) ?\s))
- (class class) cur-type display)
- (cl-dolist (tag tags)
- (when (listp tag)
- (cl-case (setq cur-type (semantic-tag-class tag))
- ((function variable type)
- (let ((type-p (eq cur-type 'type)))
- (unless (and (> depth 0) (not type-p))2Dut83xe
- (setq class nil))
- (setq display (concat (if (null class)
- spaces
- (format "%s(%s) " spaces
- (propertize (semantic-format-tag-name (semantic-tag-calculate-parent tag) nil t)
- 'semantic-tag
- (semantic-tag-calculate-parent tag))))
- (propertize (semantic-format-tag-summarize tag nil t)
- 'semantic-tag tag)))
- (message "display is %s" display)
- (and type-p
- (setq class (car tag)))
- (push (cons display tag)
- emr-c:--semantic-tag-list)
- ;; Recurse to children
- (emr-c:--semantic-fetch-candidates-helper (semantic-tag-components tag)
- (1+ depth)
- class)))
- ;; Don't do anything with packages or includes for now
- ((package include)
- (push (cons (propertize (semantic-format-tag-summarize tag nil t)
- 'semantic-tag tag)
- tag)
- emr-c:--semantic-tag-list))
- ;; Catch-all
- (t))))))
- (defun emr-c:semantic-insert-function-prototype-or-implementation ()
- "Insert function at point as prototype or implementation to
- other file (files with same names but different extensions),
- depends on file extension. If the file extension is in
- emr-c-implementation-extensions, insert \";\"; otherwise, insert
- {}. If there is more than one file, prompt for a file. If there's
- no file, prompt for the entire projectile project files."
- (interactive)
- (let (file other-files l)
- (if (featurep 'projectile)
- (progn
- (setf other-files
- (projectile-get-other-files (buffer-file-name)
- (projectile-current-project-files)
- nil))
- (setf l (length other-files))
- (setf file (concat (projectile-project-root)
- (cond ((> l 1)
- (completing-read "Select a file to insert: "
- other-files))
- ((= l 1)
- (car other-files))
- (t (projectile-find-file)))))))
- (senator-copy-tag)
- (with-current-buffer (if (featurep 'projectile)
- (find-file file)
- (ff-find-other-file))
- (emr-c:--semantic-fetch-candidates)
- (if emr-c:--semantic-tag-list
- (progn
- (setq emr-c:--semantic-tag-list (nreverse emr-c:--semantic-tag-list))
- (emr-c:--semantic-insert-prototype (cdr (assoc (completing-read "Select a place to insert: "
- emr-c:--semantic-tag-list)
- emr-c:--semantic-tag-list))))
- (emr-c:--semantic-insert-prototype nil)))))
- (defun emr-c:--semantic-insert-prototype (tag)
- "[INTERNAL] Insert a Semantic TAG to current buffer.
- If the file extension is in emr-c-implementation-extensions,
- insert \";\"; otherwise, insert {}."
- (when tag
- (semantic-go-to-tag tag)
- (goto-char (semantic-tag-end tag))
- (newline 2))
- (senator-yank-tag)
- (indent-according-to-mode)
- (if (member (file-name-extension (buffer-file-name))
- emr-c-implementation-extensions)
- (progn
- (insert "{}")
- (forward-char -1)
- (open-line 1)
- (newline 1)
- (indent-according-to-mode))
- (insert ";")
- (save-excursion
- (forward-line 1)
- (unless (c-guess-empty-line-p)
- (newline 1)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement