Getting reftex recomendations for labels when creating new sections - emacs

In TeX-latex-mode under Emacs (26.1) using the reftex minor mode,
When pressing C-c (, the command reftex-label (found in reftex-mode-map, from reftex-ref.el) gives pretty good suggestions of label according to context for sections (with the default value of reftex-insert-label-flags).
When pressing C-c C-s, the command LaTeX-section (found in LaTeX-mode-map, defined in latex.el) offers to enter a label for the section, with no suggestion (other than a prefix based on the level of the section, which is useful but much less than the one based on the title section offered by reftex-label).
How can one configure LaTeX-section to make the same suggestions as reftex-label for sections?
The hook LaTeX-section-hook along with the variable LaTeX-section-label would seem the right candidate for that purpose, but the documentation states that
Some LaTeX packages (such as fancyref) look at the prefix to
generate some text around cross-references automatically. When using
those packages, you should not change this variable.
for one, I assume that reftex is one of such packages, and second, I was expecting to be able to give a function inside a hook, not a list of prefixes, I wonder if I misunderstood what a hook is?
I think that one would "just" need to get LaTeX-section to abstain from offering a label and to call the function reftex-label immediately after each LaTeX-section call, but if it is not LaTeX-section-hook, I do not know which one it could be?
Before starting programming something which could involve stuff as complicated as refactoring both latex.el and reftex-ref.el, I thought I would ask in case I was missing an easier solution!!!

Related

Label format in RefTex

I am trying to configure RefTeX/AUCTeX so that the smart label-creation, invoked with C-c ( has the following sets of behaviors:
for \section-type labels, i.e., for \section, \subsection, etc. generate a label of the form: \label{sec:[[derived-from-section-name]]} where what follows the colon is derived from the section name.
for \items in an enumerate environment, generate a label of the form: \label{item:[[number]]}, where the number is automatically incremented from what has gone before. i.e., the first enumerate item I generate a label for gets \label{item:1}, the next one \label{item:2}, and so on.
This was standard behavior of my reftex implementation when I was using aquamacs, but I haven't been able to duplicate this in standard emacs.
Any help would be appreciated.
Try setting reftex-plug-into-AUCTeX to t like I do in my config.
Using the config linked to above the behavior is exactly how you described it. I'm on Linux, Emacs version 25.2.2, AUCTeX version 12.1.2, RefTeX version 25.2.2.

VS Code Refactoring: Change all occurences - but only in block scope

When using "change all occurences" in VS Code, it will just search the whole file for matches and change them. Is there a similar feature doing the same thing, but limiting it to function or block scope?
Let's take an example where I would need that: I'm having a React file with several components and want to refactor a class component to a functional component, so I'm changing all occurences of this.props to props. However, I obviously don't want to change all the other class components as well that are supposed to stay class components. :-)
This seems like such a standard use case, but I'm not able to find it anywhere in VS Code. If it's not possible (yet, or for some good reasons) is there another way to achieve what I'm trying to do?
Check out the 'Add Selection To Next Find Match' functionality. It allows you to highlight the first occurrence you'd like to change, then using a keyboard shortcut, highlight the next occurrence and so on until you've selected all the instances you want to change. When all to-be-changed occurrences are selected, you can edit the selected text normally. Just remember to hit the escape key a couple times after editing to return to a single cursor!
Here are the keybindings for the command, it's Cmd+d on Mac:
https://code.visualstudio.com/docs/getstarted/keybindings
I find it very useful when renaming variables, there's also a shortcut to skip occurrences (Cmd+k Cmd+d) in case there is text you don't want to change in between.

Eclipse RCP, how to highlight occurrences (or write) of selection dynamically?

As my question, I'd like to know, what need to be done to implement occurrences (or write) highlight dynamically, which like java editor does.
Current, there is good syntax highlight and basic code partitions (multiple line comment, single line comment, others). What do i need to do next for implementing the dynamical highlight?
Thanks a lot.

how to freely format comments in cc-mode

I'm quite new to cc-mode and I'd like to configure it to allow me to freely format and use tabs in multiline comments. This is important to me because I want to use cog.py in my source file and need to be able to format the python source in the comment correctly. I'd be ok with comments not beeing autoindented at all, however I'd like to keep auto indenting the rest of the source code.
Example:
...
/*
[[[cog
import cog
for x in ['a','b','c']:
>cog.outl(x)
]]]
*/
...
In the line marked with > I'd like to press TAB to indent the line. cc-mode simply does nothing at all if i do so. I could use spaces there (which is inconvenient) but every (semi-)automatic re-indentation of this block would cause the spaces to vanish and therefore the python code to be incorrectly indented (which is what happens if i happen to press tab somewhere on this line after indenting it with spaces).
I tried to start emacs without my .init to be sure this is default behavior and not modified by my configuration so far. I've done google searches and read the documentation of the cc-mode variables / functions I stumbled upon (cc-mode online docs) while searching for a solution (i.e. c-indent-comments-syntactically-p, c-indent-command, c-tab-always-indent,...) but none of these seemed to solve my question.
EDIT1:
Thanks to abo-abo's idea of a "multi-major-mode" setup i've stumbled upon mmm-mode and have set up automatic switching to python mode for a cog section, which fixes most of my problems.
The only remaining problem is reindenting the whole file or a region containing a cog section. Can I somehow tell cc-mode to not change anything in comments while reindenting the file? mmm-mode + that would be a perfect solution for me.
You can use M-i to force a tab indent on the lines that you want, so you can use it to indent your comments.
You can also change your comments to use // instead. Just select your python code snippet, and do M-x comment-region:
// def foo(x):
// print 'hi'
Then the autoindent won't mess up your indentation.

lazy loading of only the first N lines in emacs org-mode

Is there a way to tell org-mode to load only the first N lines of a long text file? I would like to keep the whole file open to be able to search through it, but have org-mode display on the first N lines of my file, which is where I edit new content.
If you have a structured outline in org-mode, you can set the global file visibility with the #+STARTUP markup, or the visibility of any heading with the VISIBILITY property, see Visibility Cycling for details. The benefit of using the built-in org-mode properties is that it's easy to have a file open up in exactly the state you want.
I have my journal file set up to accomplish something similar what I think you're asking for using these org-mode properties. The "Today" section is opened so I can see everything, but older archives are collapsed.
I'm not sure the title really fits the description?
I think you just want use buffer narrowing, which lets you hide everything outside of the specified region for as long as necessary.
You can manually narrow the buffer by marking the region and typing C-xnn
Widen the display back to the full buffer with C-xnw
I guess you could use an eval Local Variable to automate this to a pre-defined region, if you really wanted to.
There's also narrow-to-defun (C-xnd) and narrow-to-page (C-xnp). If you throw a page break into your org file (C-qC-l), the latter might prove handy.