3

What is the best solution for writing Makefile, GNU Makefile specifically?

For example:

FILES:= file0.cpp          \
        file1.cpp          \
        file2.cpp          \
        fileYetAnother.cpp

After typing the first \(or after saving the buffer), and ENTER, I want the file1.cpp to align with the file0.cpp, do not mind the \ at the end of each line, I can use align-regexp to align all of them after finished.

But it turns out this by default:

FILES:= file0.cpp  \
file1.cpp          \
file2.cpp          \
fileYetAnother.cpp

I know I can define my own indentation like Customizing indentation in makefile mode?, but it will fix the indentation to number like 4, that is not smart for different situations, what if the FILES word is long.

Besides it does not work for:

all:
        gcc ...

I have to type C-q TAB to indent the gcc ... line.

Another problem for this kind of situation, by default, if you keep typing TAB below the all: line and then type the real commands for all, Emacs will keep inserting Tab when typing TAB, AFAIK, it must be 8 spaces (a Tab exactly) at the beginning of the command line after all, so typing multiple typing-TABs should only remain one TAB.

Is there any package to handle all the messed up format in the Makefile, or you just do that manually?

CodyChan
  • 2,599
  • 1
  • 19
  • 33
  • 1
    I don't have an automatic solution, but the multiple-cursors library allows one to edit multiple lines simultaneously, so you can manually adjust several lines extremely quickly with just a couple of keystrokes. You could set up tab-stops, or a certain number of spaces to quickly indent multiple lines and likewise jump to the ends of all lines and move the back-slashes over a bit -- the same holds true for jumping to the beginning of multiple lines. I recently set up colors for multiple cursors so I can see whether I'm on an odd-col or an even-col and you could do that for tab-stops, etc. – lawlist Apr 29 '15 at 05:28
  • @lawlist yeah, I can do that using mc or other methods manually, but are all Emacs users manually doing this manually when writing Makefile or these problems cannot be automatically? I highly doubt that. – CodyChan Apr 29 '15 at 06:50
  • Why don't you abandon `Makefile`:s and use something more modern like http://www.cmake.org/ – Lindydancer Apr 29 '15 at 06:58
  • 1
    @Lindydancer It's my company's project, they don't use cmake – CodyChan Apr 29 '15 at 07:05
  • There might not be very many people actually writing complicated Makefiles... Most people try to avoid it, so I'd say no wonder the editing is uncomfortable. I wouldn't say that Automake is better... but from what I see, people prefer to generate Makefiles. To me, the only reason to ever use Make is its ubiquity, but if that's a company's internal project, I'd never hesitate to use something that is much easier to work with, SCons would be a good example. – wvxvw Apr 29 '15 at 07:22
  • 1
    @wvxvw SCons is nice, not the solution for this post though. – CodyChan Apr 29 '15 at 07:33
  • 1
    @CodyChan For a wordaround, it's easier to write Makefile by binding `TAB` to just insert a tab character in `makefile-mode`. That's what I am doing. – Tu Do Apr 29 '15 at 11:36
  • @CodyChan to make tab appear 8 spaces, simply set `tab-width` in `makefile-mode` via a hook. – Tu Do Apr 29 '15 at 11:45
  • In my Emacs, TAB is bound to insert a tab character in `makefile-gmake-mode`. I did not need to set up anything. –  Apr 29 '15 at 12:07
  • @TuDo About the "`TAB` to just insert a tab character in `makefile-mode`", what if TAB is already bound to `yas-expand` globally in the package, rebind `yas-expand` to another key? – CodyChan Apr 29 '15 at 15:22
  • @CodyChan you can simply use `M-/` and configure `hippie-expand` to expand snippets. See [my answer here](http://emacs.stackexchange.com/a/10704/200). As for Makefile, I don't recall it has any snippet or has sophisticated completion that `company` is needed. If you want to use `company` for word completion, simply configure `company` that it automatically shows popup every 0.02 second idle. – Tu Do Apr 29 '15 at 16:16
  • @TuDo I already bound `M-/` to `hippie-expand` and `yas-hippie-try-expand` is in `hippie-expand-try-functions-list`, but I didn't notice that I can use `M-/` to expand snippets, I always used `TAB` for snippets, thanks. – CodyChan Apr 30 '15 at 01:29

0 Answers0