* Customizing C Indentation
@ 2015-04-13 22:52 rdelcueto
2015-04-13 22:54 ` Rodrigo González del Cueto
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: rdelcueto @ 2015-04-13 22:52 UTC (permalink / raw)
To: help-gnu-emacs
Hey all,
I hope you could help me figure out how to customize Emacs to indent code in the following way.
I'm working on an EDK related project. And the EDK code standards state the following:
"Subsequent lines of multi-line function calls should line up one or two tab-
stops from the beginning of the function name."
Example:
Status = gRT->GetVariable(
NORMAL_SETUP_NAME,
&gEfiNormalSetupGuid,
NULL,
&VarSize,
&SystemConfiguration
);
So given a function call, the arglist-intro offset, should make reference to the position of the first character of the function being called, and from there, go up an indentation level.
I've read the Emacs documentation, and I only understood how to indent in relation to the previous line's indentation level. But I haven't been able to understand how to move within the previous line's content.
-Rodrigo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Customizing C Indentation
2015-04-13 22:52 Customizing C Indentation rdelcueto
@ 2015-04-13 22:54 ` Rodrigo González del Cueto
2015-04-14 2:54 ` Rodrigo González del Cueto
2015-04-14 21:45 ` Rodrigo González del Cueto
2 siblings, 0 replies; 4+ messages in thread
From: Rodrigo González del Cueto @ 2015-04-13 22:54 UTC (permalink / raw)
To: help-gnu-emacs
On Monday, April 13, 2015 at 5:52:49 PM UTC-5, Rodrigo González del Cueto wrote:
> Hey all,
>
> I hope you could help me figure out how to customize Emacs to indent code in the following way.
>
> I'm working on an EDK related project. And the EDK code standards state the following:
>
> "Subsequent lines of multi-line function calls should line up one or two tab-
> stops from the beginning of the function name."
>
> Example:
>
> Status = gRT->GetVariable(
> NORMAL_SETUP_NAME,
> &gEfiNormalSetupGuid,
> NULL,
> &VarSize,
> &SystemConfiguration
> );
>
> So given a function call, the arglist-intro offset, should make reference to the position of the first character of the function being called, and from there, go up an indentation level.
>
> I've read the Emacs documentation, and I only understood how to indent in relation to the previous line's indentation level. But I haven't been able to understand how to move within the previous line's content.
>
> -Rodrigo
By the way, by EDK I mean the following project: https://github.com/tianocore/edk2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Customizing C Indentation
2015-04-13 22:52 Customizing C Indentation rdelcueto
2015-04-13 22:54 ` Rodrigo González del Cueto
@ 2015-04-14 2:54 ` Rodrigo González del Cueto
2015-04-14 21:45 ` Rodrigo González del Cueto
2 siblings, 0 replies; 4+ messages in thread
From: Rodrigo González del Cueto @ 2015-04-14 2:54 UTC (permalink / raw)
To: help-gnu-emacs
On Monday, April 13, 2015 at 5:52:49 PM UTC-5, Rodrigo González del Cueto wrote:
> Hey all,
>
> I hope you could help me figure out how to customize Emacs to indent code in the following way.
>
> I'm working on an EDK related project. And the EDK code standards state the following:
>
> "Subsequent lines of multi-line function calls should line up one or two tab-
> stops from the beginning of the function name."
>
> Example:
>
> Status = gRT->GetVariable(
> NORMAL_SETUP_NAME,
> &gEfiNormalSetupGuid,
> NULL,
> &VarSize,
> &SystemConfiguration
> );
>
> So given a function call, the arglist-intro offset, should make reference to the position of the first character of the function being called, and from there, go up an indentation level.
>
> I've read the Emacs documentation, and I only understood how to indent in relation to the previous line's indentation level. But I haven't been able to understand how to move within the previous line's content.
>
> -Rodrigo
Just realized that the code example format doesn't look the same in every computer.
I'll link to the Github source code line, for a better view.
https://github.com/tianocore/edk2/blob/5d6bf9e22973c2ad327ca7422f80144c848912dc/Vlv2TbltDevicePkg/PlatformInfoDxe/PlatformInfoDxe.c#L67
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Customizing C Indentation
2015-04-13 22:52 Customizing C Indentation rdelcueto
2015-04-13 22:54 ` Rodrigo González del Cueto
2015-04-14 2:54 ` Rodrigo González del Cueto
@ 2015-04-14 21:45 ` Rodrigo González del Cueto
2 siblings, 0 replies; 4+ messages in thread
From: Rodrigo González del Cueto @ 2015-04-14 21:45 UTC (permalink / raw)
To: help-gnu-emacs
I was finally able to customize the indentation to do what I wanted. I had some trouble with nested blocks. Apparently the basic-offset (2), kept accumulating within each nested block, offsetting them by more than they should.
I guess my solution is far from elegant, but it works!
I set arglist-intro and arglist-close to use my edk-c-lineup-calls function.
Here is the code:
(defun indent-edk-func-call ()
(save-excursion
(progn
(re-search-forward "[a-zA-Z][a-zA-Z0-9]+ *(" (c-point 'eol) 'move)
(if (match-string 0)
(progn
;;(message "Matched:(%s), (%s), (%s)" (match-string 0) (match-string 1) (match-string 2))
(goto-char (match-beginning 0))
(current-column))
nil))))
(defun edk-c-lineup-calls (langelem)
;; lineup stream operators
(save-excursion
(let* ((relpos (cdr langelem))
(curcol (progn (goto-char relpos)
(current-column)))
(indent-size (indent-edk-func-call)))
(progn
;;(message "Indentation pos:(%s),(%s)" indent-size curcol)
(if (> indent-size 0)
(if (> curcol 2)
(+ indent-size 2 (- curcol))
indent-size)
(progn
;;(message "+Indentation pos:(%s),(%s)" indent-size curcol)
'+))))))
On Monday, April 13, 2015 at 5:52:49 PM UTC-5, Rodrigo González del Cueto wrote:
> Hey all,
>
> I hope you could help me figure out how to customize Emacs to indent code in the following way.
>
> I'm working on an EDK related project. And the EDK code standards state the following:
>
> "Subsequent lines of multi-line function calls should line up one or two tab-
> stops from the beginning of the function name."
>
> Example:
>
> Status = gRT->GetVariable(
> NORMAL_SETUP_NAME,
> &gEfiNormalSetupGuid,
> NULL,
> &VarSize,
> &SystemConfiguration
> );
>
> So given a function call, the arglist-intro offset, should make reference to the position of the first character of the function being called, and from there, go up an indentation level.
>
> I've read the Emacs documentation, and I only understood how to indent in relation to the previous line's indentation level. But I haven't been able to understand how to move within the previous line's content.
>
> -Rodrigo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-04-14 21:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-13 22:52 Customizing C Indentation rdelcueto
2015-04-13 22:54 ` Rodrigo González del Cueto
2015-04-14 2:54 ` Rodrigo González del Cueto
2015-04-14 21:45 ` Rodrigo González del Cueto
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).