TransWikia.com

How to automatically evaluate a cell and then jump to a specified location

Mathematica Asked on July 30, 2021

I built a new word bank of many words myself. I hope that every time I open this notebook nb file, this cell can run automatically, so that I can automatically assign a value to newwords, and then automatically make cursor jump to the cell of the query content.

enter image description here

newwords={"abate", "abbreviate", "aberrant", "ability pump", "abound", 
"abrade", "abrogate", "abscess", "abstain", "abstinence", "abstruse", 
"abut", "academician", "accede", "accessory", "accommodate", 
"accordion", "accredit", "accreditation", "acid", "hyper", 
"acidosis", "acne", "acquaint", "acquisitive", "acrophobia", 
"acropolis", "acumen", "acupuncture", "adamant", "adduce", "adept", 
"adjunct", "admonish", "admonition", "adobe", "adolescence", "adore", 
"adorn", "adulterate", "advent", "adversity", "adz", "aerobic", 
"aesthetic", "afferent", "affiliate", "affinity", "affluent", 
"afterlife", "ageism", "agile","..."};
SelectionMove[EvaluationCell[], Next, CellContents, 3(*跳转次数*)]

enter image description here

Select[newwords, 
 StringMatchQ[#, 
   "obli" ~~ __] &](*After executing the cell above, I want to jump 
to this cell automatically (this cell does not need to run 
automatically)*)

enter image description here

I want to achieve this function by modifying the cell expression of the cell where newwords is located, but how can I do this?

enter image description here

One Answer

Assuming they are consecutive cells you can do:

(*make sure this cell does not produce output because then NextCell is the output cell*)
newwords = {...};
selectCell = NextCell[];
SelectionMove[selectCell, Before, CellContents];
NotebookFind[EvaluationNotebook[], """, Next, CellContents];
SelectionMove[EvaluationNotebook[], After, Character];
Select[newwords, StringMatchQ[#, "obli" ~~ __] &]

Seems to do what you need.

Side note, consider Iconize for newwords or even move them to a separate .m file and Get it.

Correct answer by Kuba on July 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP