Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new refactor command for emr-c #5

Closed
wants to merge 1 commit into from
Closed

Conversation

tuhdo
Copy link

@tuhdo tuhdo commented Jan 26, 2015

New command: emr-c:semantic-insert-function-prototype-or-implementation.

What it does: Insert function implementation/prototype into other file (file with the same name but different extension) from anywhere in your project. It was originated from this StackExchange question.

  • If there's only one other file, the command inserts immediately into that file. Here is a demo (begins when START DEMO at the bottom):

emr-c-semantic-insert-prototype-or-implementation

In the beginning, test.h is empty. I ran the command in test.c, and it switches to test.h and insert immediately, since the file was empty. After the first function interface is inserted, when running the command on the second interface in test.c switched to test.h and prompt for a place to insert. I selected the first function inserted previously, and as a result, the second signature is inserted after it.

  • If more than one, you are prompted to select a file. Demo:

ijicd

  • If there's none, you are prompted for the entire files in your project. After you select a file, a prompt offers a list of Semantic tags in the buffer.
  • Insert prototype from .cpp to .h:

emr-c-semantic-insert-prototype-or-implementation-cpp

As you see, you can insert based on a position of a tag. Note that when point was in .cpp file, it is inside the function body; you do not have to move point to function name to do this. When the file .h was switched, the command offered a list of Semantic tags for selecting one, and insert after it. If a tag is a child of another tag, it will be appended with prefix (<parent tag name>).

  • Similarly, insert implementation body from .h to .cpp. Notice that the pair {} is opened and indented nicely, create a body to write code immeidately:

emr-c-semantic-insert-prototype-or-implementation-cpp-h-to-cpp

TODO:

  • Create an emr-menu for the command and future refactor commands.
  • Make it behave smarter: if the tag at point is a function parameter, do not offer for inserting function prototype/implementation.
  • Query all Semantic tags in current header file, filter and insert empty function definitions in corresponding source file.

New command: emr-c:semantic-insert-function-prototype-or-implementation.

What it does: Insert function implementation/prototype into other
file (file with the same name but different extension) from anywhere in
your project.

- If there's only one other file, the command inserts immediately into
  that file.

- If more than one, you are prompted to select a file.

- If there's none, you are prompted for the entire files in your
  project. After you select a file, a prompt offers a list of Semantic
  tags in the buffer.
@tuhdo
Copy link
Author

tuhdo commented Jan 26, 2015

TODO:

  • Create an emr-menu for the command and future refactor commands, similar to this menu for Emacs Lisp.
  • [IN PROGRESS] If user wants to insert a function prototype, but as a parameter of some function, that function prototype should be transformed into a function pointer.
  • Make it behave smarter: if the tag at point is a function parameter, do not offer for inserting function prototype/implementation.
  • Query all Semantic tags in current header file, filter and insert empty function definitions in corresponding source file.
  • Extract function from selected lines of code.
  • Extract constant.
  • Extract interface: collect all function signatures and put it into a class. Since we can already do this for any function, it is easy.
  • Base class generation.
  • Getter/setter generation.
  • Add proper Helm commands to provide a better interface: running helm-execute-persisten-action on a Semantic tag, by pressing TAB (or C-z, the default) should jump to that tag for previewing, and provide an action menu for listing positions to insert (i.e. currently it inserts after a selected tag, by default; we could insert before that tag, or on the same line). With Helm, it's possible to generate two or more classes into two or more different files with a single command.

@tuhdo
Copy link
Author

tuhdo commented Jan 27, 2015

I think I will create a new package of out this.

@tuhdo tuhdo closed this Jan 27, 2015
@@ -118,6 +123,56 @@ project, return all header files in the current directory."
(--filter (-contains? '("h" "hpp") (file-name-extension it)))
(-map 'file-relative-name)))


(defvar emr-c:--semantic-tag-list '()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package-private prefix should be emr-c: for consistency with the rest of the codebase, so this would be emr-c:semantic-tag-list. Same for the rest.

A double-dash prefix would be better for all of emr, but that's a topic for another changeset. :)

@chrisbarrett
Copy link
Collaborator

Very cool. Please update the identifiers as noted, then let me know when you've pushed all your commits on this feature and I'll merge. :)

@chrisbarrett chrisbarrett reopened this Jan 27, 2015
@chrisbarrett
Copy link
Collaborator

Oh, I see you closed it. Hadn't refreshed. :P Let me know if you want to proceed.

@tuhdo
Copy link
Author

tuhdo commented Jan 27, 2015

That's fine by me. I think leaving it in here would be better for everyone. Please open it again.

@chrisbarrett chrisbarrett reopened this Jan 27, 2015
@tuhdo
Copy link
Author

tuhdo commented Jan 27, 2015

This is a good reference list for future features: http://refactoring.com/catalog/

@tuhdo
Copy link
Author

tuhdo commented Feb 12, 2015

I created a package out of this: https://github.com/tuhdo/semantic-refactor

I think it's better this way since EMR has many dependencies and not all people want. The package can also be better maintained, since I take an active role over the package.

I'm sorry about this. Maybe I can integrate my package into yours at some point, as a dependency, is that ok?

@tuhdo tuhdo closed this Feb 12, 2015
@chrisbarrett
Copy link
Collaborator

No worries. Your package looks awesome. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants