Format part of a file through uncrustify - uncrustify

I would like to format only a part of a sourcefile, like a function instead of the whole file.
This is needed because i can't format the old source completle. Only the newly added functions or changes in functions should be auto formated through uncrustify.
Is a selection based formating possible with uncrustify?
Maybe it is possible to do a automatic formatting of each function which is changed through a combination of git diff --function-context and a uncrustify call.
git diff --function-context | uncrustify -xyc

You could go the other way. Save the output of git diff --function-context, then reformat the whole file, then revert the changes in lines which are not part of git diff --function-context.

Related

delete all lines starting by: INSERT INTO `mdl_logstore_standard_log` VALUES

I have a SQL text file on my Linux server, and I need to remove all lines starting by
INSERT INTO `mdl_logstore_standard_log`
Looks like a duplicate of this.
Following the "Better Solution" in the chosen answer there, you would likely want to consider using sed. This will delete the lines without needing to open the file.
For your specific case, you can run
sed '/^INSERT INTO `mdl_logstore_standard_log`/d' text_file.sql > new_text_file.sql
where you'd replace text_file.sql and new_text_file.sql with your current file and the file with lines deleted. You may also want to consider looking at the -i (or equivalent --in-place) option if you'd prefer to overwrite your previous file with the new one.
You can achieve it with vim. Open the file, type :g and then make sure you run the following:
:g/^INSERT INTO `mdl_logstore_standard_log`/d
Explanation:
- ^ is the start of the string, here means starts with
- d at the end means delete
- the pattern between the slashes is the pattern to find
If it looks good, hit :w to save your file.

IntelliJ - File watchers: wrong output of macros

I am trying to setup a file watcher for scss files which is working on files with a filename not starting with _.
But if I have a file named _file_name.scss the output of any macros that include the filename will be file.name.scss.
The first _ is removed and following ones are replaced by ..
Even though in the insert macros selection tool I can see that the output when you select a macro is correct.
Like $FilePathRelativeToProjectRoot$ will display mypath/_file_name.scss in the selection tool but then my command from this file watcher will output mypath/file.name.scss.
Am I missing a parameter here ?
Full configuration:
For me, existing file names are not changed when using similar file watcher. But files with names starting the _ are not prettified, the main .scss that includes them is processed instead.
To avoid this, try adding COMPILE_PARTIAL=true variable to your file watcher settings:
Also, make sure that Track only root files is off.
See the comments in https://youtrack.jetbrains.com/issue/WEB-13459

Include the last changed date of the source in a ReStructuredText file

I have a project with documentation written in ReStructuredText. The docs are compiled to HTML when the project is built via cmake. It includes a line with a "last changed" date.
I wonder how hard it would be to set this date automatically, as, from time to time, I simply forget to update the last changed date when I edit the docs.
I thought about generating some additional file, like
date -d "#$(stat -c %Z Readme.rst)" +"%d.%m.%Y" > lastchange.txt
and to reference it in the source like
:Date: .. include:: lastchange.txt
But would it be possible to achieve such a reference with only RST? Or in a more elegant way? Because doint it like so, it would be necessary to create a "working copy" of the sources in the cmake build directory, because otherwise the reference won't be found. And if I do this, I can as well sed the date into the sources directly.

IntelliJ: Dynamically updated file header

By default, IntelliJ Idea will insert (something like) the following as the header of a new source file:
/**
* Created by JohnDoe on 2016-04-27.
*/
The corresponding template is:
/**
* Created by ${USER} on ${DATE}.
*/
Is it possible to update this template so that it inserts the last date of modification when the file is changed? For example:
/**
* Created by JohnDoe on 2016-03-27.
* Last modified by JaneDoe on 2016-04-27
*/
It is not supported out of the box. I suggest you do not include information about author and last edit/create time in file at all.
The reason is that your version control system (Git, SVN) contains the same information automatically. So the manual labelling is just duplicate of already existing info, but is only more error prone and needs to be manually updated.
Here's a working solution similar to what I'm using. Tested on mac os.
Create a bash script which will replace first occurrence of Last modified by JaneDoe on $DATE only if the exact value is not contained in the file:
#!/bin/bash
FILE=src/java/test/Test.java
DATE=`date '+%Y-%m-%d'`
PREFIX="Last modified by JaneDoe on "
STRING="$PREFIX.*$"
SUBSTITUTE="$PREFIX$DATE"
if ! grep -q "$SUBSTITUTE" "$FILE"; then
sed -i '' "1,/$(echo "$STRING")/ s/$(echo "$STRING")/$(echo "$SUBSTITUTE")/" $FILE
fi
Install File Watchers plugin.
Create a file watcher with appropriate scope (it may be this single file or any other scope, so that any change in project's source code will update modified date or version etc.) and put a path to your bash script into Program field.
Now every time the file changes the date will update. If you want to update date for each file separately, an argument $FilePath$ should be passed to the script.
This might have been just a comment to #oleg-mikhailov excellent idea, but the code snippet won't fit. Basically, I just tweaked his solution.
I needed a slightly different syntax but that's not the issue. The issue was that when the script ran automatically upon file save using the File Watchers plugin, if ran on a file which doesn't include PREFIX it would run over and over for ever.
I presume the that the issue is with the plugin itself, as it didn't happen when run from the shell, but I'm not sure why it happened.
Anyway, I ended up running the following script (as I said only a slight change with respect to the original). The new script also raises an error if the the prefix doesn't exist. For me this is a feature as Pycharm prompts me with the error, and I can fix the file.
Tested with PyCharm 2021.2.3 on macOS 11.6.
#!/bin/bash
FILE=$1
DATE=`date '+%Y-%m-%d'`
PREFIX="last_modified_date: "
STRING="$PREFIX.*$"
SUBSTITUTE="$PREFIX$DATE"
if ! grep -q "$SUBSTITUTE" "$FILE"; then
if grep -q "$PREFIX" "$FILE"; then
sed -i '' "s/$(echo "$STRING")/$(echo "$SUBSTITUTE")/" $FILE
else
echo "Error!"
echo "'$PREFIX' doesn't appear in $FILE"
exit 1
fi
fi
PHPStorm has not a "hook" for launching task after detect a change in file (just for uploading in server yes). Code templating is based on the creation of file not change.
The behaviour you want (automatic change file after manual change file) can be useful for lot of things but it's circular headhache for editor. Because if you change a file it must change file (and if a file is change ? it change file ?).
However, You can, perhaps, "enable Live Templates" when you launch a "reformat code" which able to rewrite your begin template code that way rewrite date modification.
Other solution is that use a tools with as grunt but I don't know if manage php file.

In texinfo, how to specify a bash single quote?

I am writing a package using the GNU build system. The documentation hence is in the texinfo format. As a result, executing make converts the texinfo file into the info format, and executing make pdf automatically produces a pdf file.
In the texinfo file, I have something like this:
#verbatim
awk '{...}' data.txt
#end verbatim
However, in the pdf, the "basic" single quotes (U+0027) in the awk command above are transformed into "curvy" single quotes (U+2019) so that, if one does a copy-paste of the command from the pdf into a terminal, bash complains ("syntax error"). This forces the user to edit the command he just copy-pasted. Same problem occurs if I replace #verbatim by #example. I searched the texinfo manual but couldn't find a way to specify apostrophes. I am using texinfo version 5.2.
Karl Berry (via the bug-texinfo mailing list) told me to add 2 lines to my texi file (more info):
#codequoteundirected on
#codequotebacktick on
as well as add the latest version of texinfo.tex to my package.