My Emacs default indent like this:
arr = {
'a',
'b',
'c',
'd'
}
but I want it like this:
arr = {
'a',
'b',
'c',
'd'
}
How can I do ?
I use python-mode, Emacs version: 24.4.50.1.
Thanks.
Shipped python.el as python-mode.el set symbol major-mode likewise onto python-mode - see M-x describe-variable RET major-mode RET.
From python-mode.el --it displays "Py" in modeline-- you could customize
py-closing-list-dedents-bos to t
Suffix "-bos" stands for beginning-of-statement, i.e. its indentation.
Related
I have a vast array list like below
$data= [
'user_name' => 's',
'user_place' => 'a',
'address_list_code' => 's',
'block_number' => 3,
];
so I want to replace the key string with all uppercase.I know to convert selected text to uppercase using vs code shortcut Ctl+Alt+u and it works.
But I want to select only all keys in between a single quote and make it uppercase so the expected output is
[
'USER_NAME' => 's',
'USER_PLACE' => 'a',
'ADDRESS_LIST_CODE' => 's',
'BLOCK_NUMBER' => 3,
];
Even I tried this extension but not suceded to select all text in between single quotes
https://marketplace.visualstudio.com/items?itemName=dbankier.vscode-quick-select&ssr=false#version-history
Check out this fiddle : https://jsfiddle.net/m82ycfxw/
I made a normal JS code to convert the desired text to upper case.
This might be a temporary thing but I hope this will work for you.
let str = `
$data= [
'user_name' => 's',
'user_place' => 'a',
'address_list_code' => 's',
'block_number' => 3,
]
`;
var regex = /'[a-z_]+' =>/g;
str = str.replace(regex, foundText => {
return foundText.toUpperCase();
});
console.log(str);
Just change the str variable. Put all your complete data object inside backticks (` `)and run the code.
The extension Select By could help.
Place cursors at the start of the lines where you want to Uppercase text
with MoveBy: Move cursors based on regex move to the next '
with SelectBy: Mark positions of cursors
with MoveBy: Move cursors based on regex move to the next '
with SelectBy: Mark positions of cursors (create selections)
execute: Transform to Uppercase
Esc to exit multi Cursor
Sure, you can do this natively:
In settings.json, temporarily remove _ as a word separators (e.g. "editor.wordSeparators": "!##$%^&*()-=+[{]}\\|;:'\",.<>/?,) (Notice no _)
.
Place cursors at beginnings of all desired lines.
Right arrow to move all cursors within the quotes.
Execute command expand selection. Since you turned off _ as a word delimiter, this will expand to fill the quotes; otherwise, all the keys would need to have the same number of words for this to work.
Execute upper case.
In settings.json re-add _ to word separators.
Easy with Find and Replace. See regex101 demo
Find: (^\s+')([^']*)'
Replace: $1\U$2'
The \U will uppercase the following capture group $2.
Starting the find at the beginning of the line with ^ makes it easy to target just the "keys" (the first '-delimmited strings) and not the other following strings.
I have the following variables set in my org-mode file:
* conf
# local variables:
# org-agenda-start-on-weekday: 1
# org-clock-report-include-clocking-task: t
# org-duration-format: (quote h:mm) #fails
# end:
They all work great, except for org-duration-format. What am I doing wrong?
(I say it doesn't work because I have to run (setq org-duration-format 'h:mm) to get my preferred format.
The file-local-variables section of the emacs manual (C-h i g (emacs) specifying file variables RET) says:
the variables in a local variables list are used literally, and are not evaluated first.
So just use h:mm literally:
...
# org-duration-format: h:mm
...
You can also do something like this:
...
# eval: (setq-local org-duration-format 'h:mmm)
...
but there is really no need to do that.
This has nothing to do with Org mode BTW. Try
# Local Variables:
# bar: 3
# foo: bar
# End:
The file-local value of bar is 3; the file local value of foo is bar: bar is NOT evaluated, so foo does NOT end up with the value 3.
I am trying to build my major mode for syntax highlighting log files from a certain tool flow.
and I've been using this excellent guide to get started
http://ergoemacs.org/emacs/elisp_syntax_coloring.html
but I would like to highlight "*W", "*E" and "*F"
but I cannot get that to work
here are my font-lock keywords
(setq mylog-font-lock-keywords
(let* (
;; define several category of keywords
(x-warnings '("UVM_ERROR" "UVM_FATAL" "^.*E" "F"))
(x-keywords '("UVM_INFO" "NOTE" "Note"))
(x-types '("UVM_WARNING" "*W," "xmsim"))
(x-constants '("ACTIVE" "AGENT" "ALL_SIDES" "ATTACH_BACK"))
(x-events '("at_rot_target" "at_target" "attach"))
(x-functions '("llAbs" "llAcos" "llAddToLandBanList" "llAddToLandPassList"))
;; generate regex string for each category of keywords
(x-keywords-regexp (regexp-opt x-keywords 'words))
(x-types-regexp (regexp-opt x-types 'words))
(x-constants-regexp (regexp-opt x-constants 'words))
(x-events-regexp (regexp-opt x-events 'words))
(x-functions-regexp (regexp-opt x-functions 'words))
(x-warnings-regexp (regexp-opt x-warnings 'words))
)
`(
(,x-types-regexp . font-lock-type-face)
(,x-constants-regexp . font-lock-constant-face)
(,x-events-regexp . font-lock-builtin-face)
(,x-functions-regexp . font-lock-function-name-face)
(,x-keywords-regexp . font-lock-keyword-face)
(,x-warnings-regexp . font-lock-warning-face)
;; note: order above matters, because once colored, that part won't change.
;; in general, put longer words first
)))
;;;###autoload
(define-derived-mode mylog-mode verilog-mode "log mode"
"Major mode for editing LOG FILES…"
;; code for syntax highlighting
(setq font-lock-defaults '((mylog-font-lock-keywords))))
(set-face-foreground 'font-lock-type-face "yellow")
;; add the mode to the `features' list
(provide 'mylog-mode)
as you can see I've tried a few things with out success.. any other words are highlighted correctly?
as a final touch I would like to for all occurenses of WARNING or ERROR I would like to highlight the entire line until EOL.
I have found some examples but none that show how to highlight until EOL in a major mode lisp file
This is an example (taken from my init.el). Hope it help.
(font-lock-add-keywords nil
'( ; high-light full line ending with "E" or "FATAL"
("^.*\\(E\\|FATAL\\)$" . 'font-lock-function-name-face)
; high-light full line beginning with '*E' '*F' '*W'
("^\\*[EFW]\\b.*$" . 'font-lock-comment-face)
; high-light only ending part of the lines which contain "F"
("\\b\\w*F$" . 'font-lock-function-name-face)
; high-light from "UVM" to end of line
("\\bUVM.*$" . 'font-lock-function-name-face)
; high-light only words that end with "G"
("\\b\\w*G\\b" . 'font-lock-function-name-face)
; bold things between 2 **, like **bold**
("\\*\\*.+?\\*\\*" . 'bold)))
I'd like to adjust indentation of my source code correctly at a time after I select some block of it.
Is there any function or key with which I can do it including parenthesis?
Here is original selected block of sample code I'd like to adjust indentation.
while(1)
{
func1();
if( )
{
func2();
}
}
if( x == 0 )
{
aa = 1;
}
This would be the correctly indented code how I just want to adjust.
while(1)
{
func1();
if( )
{
func2();
}
}
if( x == 0 )
{
aa = 1;
}
Select your code and press C-M-\, which should be bound to indent-region:
C-M-\
Indent all the lines in the region, as though you had typed TAB at the beginning of each line (indent-region).
If a numeric argument is supplied, indent every line in the region to that column number.
I'm using evil mode because I like vim editing keymap.
In my case, block auto indentation can be done by equal(=) key after selecting a code block.
It's very convenient to rearrange block of code in a c-default-style.
(1) install evil package
(2) Insert this code into you emacs init file.
; indentation style for c, c++, java
(setq c-default-style "linux"
c-basic-offset 4)
(3) select block using v and direction key
(4) press '='
I saw this somewhere, but cannot find it now.
Is there a built-in function in emacs, or does someone have elisp, to line up all the equals signs in a series of inititialization statments in cc-mode?
Before:
int t=9;
Graphics g = new Graphics();
List<String> list = new List<String>();
After:
int t = 9;
Graphics g = new Graphics();
List<String> list = new List<String>();
Use M-x align-regexp (here, M-x align-regexp RET = RET). You can also add an "alignment rule" to the variable align-rules-list, so that in future M-x align will do it. See the documentation (C-h f align) for details.
This is in response to harpo's comment to ShreevatsaR's answer:
The only problem with this is that it "tabifies" the output, which is probably not what you want. Do you know any way to prevent this?
Here's what I did to resolve that issue:
;; Align with spaces only
(defadvice align-regexp (around align-regexp-with-spaces)
"Never use tabs for alignment."
(let ((indent-tabs-mode nil))
ad-do-it))
(ad-activate 'align-regexp)
M-x align should do the trick.