Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8256283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:48:46+00:00 2026-06-08T01:48:46+00:00

I’m trying to define a command to customize my C/C++ function definitions in emacs.

  • 0

I’m trying to define a command to customize my C/C++ function definitions in emacs.

What I’d like to obtain is to automatically reformat the code to look like this:

type func(type arg1,
          type arg2,
          ...
          type argN) {

starting from a generic declaration such as:

type func(type arg1, type arg2, ..., type argN) {

My idea was to search for the specific pattern of a function definition, and replace it with itself with a new line after each comma, and then adjust the indentation.

I messed around for a while with regexp and so on, but I couldn’t come up with anything.

I can’t figure out how to properly perform replacement within the string obtained using my regex.

What follows is everything I got so far, which basically is almost nothing.

(defun fix-arg-definition ()
  (interactive)
  (goto-char (point-min))
  (replace-regexp "([^,()]+\\([,][^,()]+\\)+)[ ]*{" "WHAT TO PUT HERE?")
)

I’m completely new to the world of customizing coding style in emacs, and this has proven more difficult than I thought. Any help is appreciated.

UPDATE

I’ve managed to get something that seems to work, although I’ve still got to try test it thoroughly.

(defun fix-args ()
  (interactive)
  (goto-char 1)
     (while (search-forward-regexp "\\(([^,()]+\\([,][^,()]+\\)+)[ ]*{\\)" nil t) 
     (replace-match (replace-commas) t nil)))

(defun replace-commas ()
   (let (matchedText newText)
       (setq matchedText
       (buffer-substring-no-properties
       (match-beginning 1) (match-end 1)))
   (setq newText
   (replace-regexp-in-string "," ",\n" matchedText) )
 newText))

I can live with this, and then adjust the indentation manually with another command, at least for now.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:48:47+00:00Added an answer on June 8, 2026 at 1:48 am

    You can do this easily by recording a keyboard macro:

    Here is one I prepared earlier shown through edit-named-kbd-macro.

    ;; Keyboard Macro Editor.  Press C-c C-c to finish; press C-x k RET to cancel.
    ;; Original keys: M-C-a C-SPC M-C-n <<replace-regexp>> , RET , C-q LFD RET M-C-a C-SPC M-C-n TAB
    
    Command: c-split-formal-params 
    Key: none
    
    Macro:
    
    M-C-a           ;; c-beginning-of-defun
    C-SPC           ;; set-mark-command
    M-C-n           ;; forward-list
    <<replace-regexp>>  ;; replace-regexp
    ,           ;; c-electric-semi&comma
    RET         ;; newline
    ,           ;; c-electric-semi&comma
    C-q         ;; quoted-insert
    LFD         ;; newline-and-indent
    RET         ;; newline
    M-C-a           ;; c-beginning-of-defun
    C-SPC           ;; set-mark-command
    M-C-n           ;; forward-list
    TAB         ;; c-indent-line-or-region
    

    Having a better understanding of structural navigation commands like
    beginning-of-defun and forward-list will also help you.

    For more in depth discussions of keyboard macros see the manual and my previous answers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.