function-args icon indicating copy to clipboard operation
function-args copied to clipboard

Add body insertion for virtual/orerriden functions

Open tuhdo opened this issue 11 years ago • 2 comments

Currently, moo-virtual and moo-override can insert function interfaces inside a class. I think, it would be beneficial if it can insert function bodies, that is function interface + braces (so, instead of inserting ;, it insert { } anywhere in the file. We can choose multiple function interfaces for insertion into current buffer. Each insert is separated by a blank line.

Now, suddenly we have a nice feature for function interface implementation in other IDEs.

How do you think?

tuhdo avatar Aug 25 '14 08:08 tuhdo

It could be added, but I like it as is since there are too many preferences to consider when doing what you ask (different whitespace, different behavior in headers, whatever). For instance, when I write a constructor, I don't need curly braces straight away. That's why I have a custom function that inserts curly braces:

(defun ins-c++-curly ()
  "Insert {}.
Threat is as function body when from endline before )"
  (interactive)
  (cond ((eq major-mode 'term-mode)
         (term-send-raw-string "{}")
         (term-send-raw-string ""))
        ((looking-back "\\()\\|try\\|else\\|const\\|:\\)$")
         (insert " {\n\n}")
         (indent-according-to-mode)
         (forward-line -1)
         (indent-according-to-mode))
        ((region-active-p)
         (let ((beg (region-beginning))
               (end (region-end)))
           (deactivate-mark)
           (goto-char beg)
           (insert "{")
           (goto-char (1+ end))
           (insert "}")))
        (t
         (insert "{}")
         (backward-char))))

This function also does the whitespace after try/else/const in the style that I like. Give it a try.

And of course I'm happy to accept patches if you want to add the customization that you suggest.

abo-abo avatar Aug 26 '14 17:08 abo-abo

Helm added an action not too long ago that allows any candidate in Helm to be inserted as it is when execute C-c C-i and do not move point at the end of candidate. So, essentially you can use it to insert candidates from moo-virtual and moo-override the way it is currently. Would it be possible to use that action and in combination with your ins-c++-curly to insert necessary text into the buffer, then indent the inserted region?

Sure, I will try to see if I can do something.

tuhdo avatar Aug 26 '14 17:08 tuhdo