Clang-Format: How to specify a custom format options file? - clang-format

I'm trying to configure a custom style options file for clang-format v6.0.0 running on Windows 10 Pro 64-bit. I started out by generating an options file based upon the llvm style using the following command line, which worked fine:
clang-format -style=llvm -dump-config > .clang-format
The documentation for clang-format states the following:
"When the desired code formatting style is different from the available options, the style can be customized using the -style="{key: value, ...}" option or by putting your style configuration in the .clang-format or _clang-format file in your project’s directory and using clang-format -style=file."
So just as a test I used the unchanged .clang-format file I generated above and used the following command line:
clang-format -style=.clang-format Test.c
The result was a message that said
"Invalid value for -style"
I then changed the name of .clang-format to _clang-format and tried it again but the result was the same. So, my question is, "How do I specify a specific style options file?"

As you correctly discovered command is expecting the literal -style=file. For example clang-format.exe -i -style=file The -i option is to execute the changes in place. The -style=file is telling the program to look in the current directory for the configuration file named .clang-format or _clang-format Configuration options. If the config file is still not found the program will move up a directory and continue searching and so on. More command line documentation can be found here.

Related

how to invoke clangd to format a file

I have a workable version of clangd in my bin, but there is no clang-format. I want to format a file from command line, how to do this?
In clangd doc, it says
clangd embeds clang-format
A standalone clang-format can directly format a file from command line. I don't know whether clangd can do the same.

Sublime Text 3 LaTeXTools plugin won't compile on Debian

When doing Ctrl+B on SublimeText3, the following error is output:
[Compiling first.tex]
TraditionalBuilder: Invoking latexmk...
COULD NOT COMPILE!
Attempted command:latexmk -cd -e $pdflatex='pdflatex -interaction=nonstopmode -synctex=1 %S %O' -f -pdf first.tex
Build engine: Traditional Builder
Running the exact same command compiles a pdf file just fine.
This answer does not solve the problem, as I've
Removed spaces around "="
Done a "Reconfigure LaTeXTools and migrate settings".
Made sure pdflatex is installed.
Made sure the path for texpath is correct.
If your command runs on terminal then most likely there is an issue either with the path or with the command itself (in the file). There has been some update to the README file by the developer:
some distros do not want a space before and after the = in $pdflatex = %E. But some do want the space there (sigh!)
sometimes latexmk is not on the PATH, or the path is not correctly picked up by ST. In this case, instead of "latexmk", use "/usr/bin/latexmk" or wherever latexmk is in your system.
some distros require quoting the $pdflatex assignment, as in "$pdflatex = \"'%E -interaction=nonstopmode -synctex=1 %S %O'\""
So it might take a while but you'll find it eventually in the settings or the traditionalbuilder.py file.
Also when I tried putting /usr/bin/latexmk, latex did not produce the correct pdf (I checked it with few changes and it just opened the old pdf) but in your case it might work.
Also, at least in Arch Linux I can't run sublime with sublime-text but instead with subl so I changed that too in the settings (I don't know if it actually matters) and I needed to change the permissions for the files because user-run sublime could not access my settings files!

What do I need to do to "register" 'latexpdf' for Sphinx?

When I run Sphinx using 'latexpdf' I get an error, even though I have a complete working TeX installation on my machine:
Sphinx error: Builder name latexpdf not registered
What do I need to do to "register" latexpdf?
latexpdf is not a Sphinx builder; it is the name of a target in the Makefile created by sphinx-quickstart. This target uses the latex builder.
Executing sphinx-build -b latexpdf . _build produces the error in the question (as expected).
If you run make latexpdf, it works.
PyCharm was mentioned in a comment and the problem seems to stem from that program. The following is run when latexpdf is configured as a "Command" (Sphinx task):
sphinx_runner.py -b latexpdf <indir> <outdir>
The sphinx_runner.py script is very similar to sphinx_build (a wrapper for sphinx.cmdline.main()). Since the -b option is supposed provide the name of an actual builder, there is an error.
Use -M instead of -b. This invokes sphinx-build similarly to make latexpdf, e.g.:
sphinx-build -M latexpdf . _build
See #mzjn's answer for details.
Now have Pycharm 2016.3 generating a pdf form me based on information here: https://www.quora.com/How-to-create-a-PDF-out-of-Sphinx-documentation-tool
Install rst2pdf:
pip install rst2pdf
Edit a new Python Docs sphinx configuration and choose pdf as the command. Set input directory and directory to hold .pdf as output.
Edit the conf.py file and add the two lines that mention pdf:
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
'rst2pdf.pdfbuilder'
]
pdf_documents = [('index', u'documentation', My Docs', u'Me'), ]
Now run the configuration and you should get a file called documentation.pdf in the output directory.
If you are interested in a pure Python solution, the following works for me:
import sphinx.cmd.make_mode as sphinx_build
OUT_DIR = "docs" # here you have your conf.py etc
build_output = os.path.join(OUT_DIR, "_build")
# build HTML (same as `make html`)
build_html_args = ["html", OUT_DIR, build_output]
sphinx_build.run_make_mode(args=build_html_args)
# build PDF latex (same as `make latexpdf`)
build_pdf_args = ["latexpdf", OUT_DIR, build_output]
sphinx_build.run_make_mode(args=build_pdf_args)
In fact, I've made a complete Python3 script that given a few convenient arguments generates the whole package documentation as HTML and PDF from scratch, with the RTD theme. It can be pretty handy if you want it to run it on different OS or Python interpreters (in my case i wanted to run it within Blender), or adapt it to your needs. It still has some dirty spots, due to some variables being hardcoded into conf.py. Let me know if you see any issues with it!
This is how it looks like:
HTML
PDF
Cheers,
Andres

Adding a new build rule to parse all rtf files

Xcode includes a flexible build rules system. The documentation is all but non-existant however.
A project I am working on for iOS 5 and iOS 6 includes an rtf help file. For iOS 6, I can convert the rtf file into an archived NSAttributedString object, then load that at runtimeand display it directly to a UITextView. For iOS 5, I can't (without a lot of work in Core Text...) so I want just the text without the style info.
I wrote a command line tool, RTFToData that takes an RTF file as input and generates a .txt file and a .data file (where the .data file contains a version of the styled text that my project knows how to use.)
Here is the syntax of my command line tool:
RTFToData [-o] source_path [destination_path]
-o (optional) overwite existing files
source_path (required) path to source RTF file (must have extension "rtf" or "RTF"
destination_directory (optional.) writes output files to source file directory if no destination specified
destination_directory must exist if specified.
I want to set up my project so that I can add .rtf files as sources (with the "add to target" checkbox NOT checked.) I want Xcode to run my RTFToData command on each file specifying that the output files should be copied into a directory and then added to the target.
Ideally, I'd like the build process to know about the dependencies between my source .rtf files and the processed .data and .txt files. If I touch a .rtf file, I'd like the build process to re-run the rtftodata command.
I am a makefile and unix scripting neophyte. I THINK I can use a run script build rule that will do this, but I am unclear on how. I guess I need to write a script that finds all files of type ".rtf", pipes that list of files into an invocation of my RTFToData.
Can somebody outline the steps I need to take in the Xcode IDE to make my project handle this smoothly?
As a side-note, is there some directory where you can put command line tools so they are available to the current version of Xcode? So far I've been installing the RTFToData command in /Library/usr/bin, but I'd really like the build tool to be included in the project, or at the very least, not have to use sudo to set up every development machine that is used to build this project.
Create a custom build phase
Add the .rtf files to your project and make sure they are added to your target.
Go to your target settings and select the "Build Rules" tab:
Click the "Add Build Rule" button at the bottom.
You want to configure your rule based on something like this:
Enter a standard wildcard glob for the files you want to match (*.rtf).
Inside the script section you can make use of a number of environment variables. Assuming your glob has matched the input file Test.rtf you have access to these vars:
INPUT_FILE_PATH = /path/to/your/project/source/Test.rtf
INPUT_FILE_NAME = Test.rtf
INPUT_FILE_BASE = Test
INPUT_FILE_SUFFIX = .rtf
INPUT_FILE_DIR = /path/to/your/project/source/
You want to process your file and send it to the ${DERIVED_FILES_DIR} directory with whatever new filename or extension you need. In this case we take the base filename from the input and give it a new extension.
Fill out the "Output Files" section with the same output file you used in the script. This will ensure the dependency system works and that the file will be copied to your .app. The script will only be run if the input has changed or the output file is missing from the .app.
Note that the "Output Files" should not have double quotes. The paths will be quoted for you by Xcode.
If your script generates multiple output files, add extra entries for those as well.
Once this is all set up, .rtf files added to your target will be converted to whatever output files your script generates. The original .rtf files will not exist in the final .app.
Where to put scripts/programs
As a side-note, is there some directory where you can put command line
tools so they are available to the current version of Xcode?
Put your tools somewhere below the directory that contains your .xcproject. Then from your build phase/rules use the ${SRCROOT} environment variable, which is the directory containing your project:
Assuming this file system layout:
/path/to/project/project.xcodeproj
/path/to/project/Tools/CommandLineTool
Use this in your build phase/rules:
"${SRCROOT}/Tools/CommandLineTool" "${INPUT_FILE_PATH}" ...
Remember to use double-quotes everywhere you can!

DCC32 compiler configuration file and command line parameter precedence

I am trying to build first time my Delphi application through command line using DCC32. I have few doubts regarding the configuration file of my project. There are some search paths I have to add to project when compiling through IDE. When I remove them, the compilation fails.
Now if I compile it through command line is it need to specify configuration file details or the search path parameters?
without any parameters:
dcc32.exe project1.dpr
with some parameters:
dcc32.exe -u%Shared% -ND:\out project1.dpr
I have following doubts:
if the config file details are not mentioned then it will take settings automtically from project.cfg (created by IDE)??
if yes then if i mentioned the -U,-N options in command line then it will override All the settings which are in .cfg ile?
This question sounds foolish but want to know What is use of compiling through command line over IDE?
Please provide some help to resolve my doubts. Any information related to dcc32 compilation options will be appreciated.
1. - If the project config file is not specified in the command line options, will the settings be taken from the project's cfg file generated by IDE ?
Yes.
2. - When I use the -U, -N options in command line will that override all the settings from a project cfg file ?
No. Command line options takes precedence though, but only those options you specify will override the settings from the project's *.cfg file, not the whole configuration
3. Is there a difference between compilation from command line and compilation from IDE ?
No. There is no difference speaking about Delphi 5. From my view, the command line way just brings you the possibility to automate a build process through command line batch without need of opening IDE.
It's been a while, but I believe you are correct in your assumptions about the command-line vs the .cfg file. You can verify this yourself by having one path in the .cfg and specifying a different one on the command line and, say, have an error in the file that the .cfg would reference and see if the compiler hits the error.
Compiling from the command-line is convenient for automated build systems but is otherwise the same as compiling through the IDE.

Resources