emacs semantic windows inconsistent - emacs

At work we have quite a large code base and I am really, really trying to get Semantic to just work. Yesterday it seemed to have parsed the file I was working on as well as the non-system includes: Great. I could create an instance of a class which is defined in another include file and after construction I could browse through all the functions etc with a key binded to semantic-ia-complete-symbol-meu.
Firstly, I am using:
Emacs 24.3.1 with
CEDET bzr version: rev_8678.tar.gz and, all of this is running on
Windows 7 (unfortunately).
MinGW and MSYS installed
Microsoft Visual Studio 10
In my .emacs (related to CEDET stuff):
;; MODE: CEDET
(load-file "~/.emacs.d/cedet/cedet-devel-load.el") ;; This is the latest dev' version ~~ 26th Sept 2014
;; Add further minor-modes to be enabled by semantic-mode.
;; See doc-string of `semantic-default-submodes' for other things
;; you can use here.
(add-to-list 'semantic-default-submodes 'global-semantic-idle-summary-mode t)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-completions-mode t)
(add-to-list 'semantic-default-submodes 'global-cedet-m3-minor-mode t)
(semantic-mode 1)
(global-ede-mode 1)
;(global-semantic-decoration-mode)
;(setq semanticdb-default-save-directory "~/.emacs.d/.semanticdb/")
;(add-to-list 'magic-fallback-mode-alist '("^// " . c++-mode))
;(add-to-list 'magic-fallback-mode-alist '("^#include" . c++-mode))
;(semantic-add-system-include "c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include" 'c++-mode)
;(semantic-add-system-include "/usr/include/c++/3.4.4")
Therefore, my default semantic database location is ~/.emacs.d/semanticdb
I come in today and find that when I load the same file up I keep on getting three errors (both of which I have searched for but nothing matches my issue):
Parsing main.cpp (LL)...
Idle Parse Error: "#<buffer main.cpp> - End of buffer"
And
Save Error: nil: c:/Users/[MY_USER]/.emacs.d/semanticdb/!drive_[STUFF_HERE]!semantic.cache
And
Idle Service Error semantic-idle-summary-idle-function: "#<buffer main.cpp> - End of buffer"
As I said, this was working yesterday, so why not today? (PS: Btw, this only happens with main.cpp - when I search for definitions of functions using xcscope and open the definition up the file is parsed correctly with CEDET and local includes are parsed and I can symbol-lookup, it seems to just be main.cpp for some reason.)
PS: I have just read a similar problem that someone has with MATLAB. The solution was to either create the directory stated in the matlab-include path, or change the list in the path. But, this does not make sense to my situation because this was working yesterday and I have not touched CEDET since yesterday at all.
semantic-c-dependency-system-include-path is a variable defined in `c.el'.
Its value is ("/usr/include")
semantic-dependency-include-path is a variable defined in `dep.el'.
Its value is nil
Local in buffer main.cpp; global value is the same.
Both of these are the same as yesterday.
PS: Also, when semantic-mode is enabled I am no longer to use (imenu-add-to-menubar) - I only get the option to rescan everything. However, when I do not have semantic-mode enabled then this works fine. I did not know that semantic messed with imenu unless you told it to?
It is all a little annoying because I really like the potential of CEDET/Semantic and appreciate the work that has been put into it. Emacs is already powerful, but with a fully working CEDET its power tends to over 9000!
I believe the developers involved with CEDET should run tests on a Windows machine so that any bugs can be found with Windows issues. I know the OS is horrible but some developers are forced to use it in the workplace. I have never found an issue with CEDET so far on my Linux machines because things are in standard places! But, this is about Windows.
PS: If it is any help a very simple project works fine with this set up and CEDET. I have, in a completely different place:
emacs_test_semantic> ls -l
total 103
-rw-r--r-- 1 [USER] Administrators 43 Oct 2 17:28 Makefile
-rw-r--r-- 1 [USER] Administrators 158 Oct 8 12:04 main.cpp
-rw-r--r-- 1 [USER] Administrators 247 Oct 1 12:51 myClass.cpp
-rw-r--r-- 1 [USER] Administrators 159 Oct 1 12:51 myClass.hpp
-rwxr-xr-x 1 [USER] Administrators 99862 Oct 2 17:28 output.exe
And, in the main:
#include <list>
#include "myClass.hpp"
using namespace std;
int main() {
MC CLASS( 3, 5 );
list<MC> myList;
myList.
return 0;
}
So, I am able to complete symbols of the MC class, however, not the STL list. BUT, this is topic is not about being able to complete STL functions/templates because there are many questions on this.
This small project, even though with (global-semantic-decoration-mode) enabled and a RED over #include <vector> does not give the same three errors described above. Also, imenu works!
===
In summary, I am somewhat confused as to the inconsistency, here. The fact that in the large code base things worked yesterday, but now I have these three errors that I didn't get before!
===
PS: Just after I wrote this I load up that same file and this time global-decoration-mode shows that the local includes are actually now understood! Even though I have changed nothing. So now it seems to work again - but it is this inconsistency which is not understandable.
Well, it works for one branch and not for another. Interestingly, in the branch that gives me the three errors (indicated above) I have a DB file (and imenu does not work, and nor is decoration-mode visable:
-rw-r--r-- 1 [USER] Administrators 449 Oct 8 13:42 !drive_d![SOME_STUFF]!semantic.cache
Compared to the one that works which is (where, global-decoration-mode is visible and imenu works):
-rw-r--r-- 1 [USER] Administrators 555184 Oct 8 13:51 !drive_d![SOME_STUFF]!semantic.cache
You can see the big difference in size. And these two branches only differ in a completely different location in the code base. So, just some extra information.
===
As a user of CEDET/semantic (albeit, not a very good one) I would really like to know a way to manually FORCE the parsing of all files in a given list that is wrote to the DB rather than relying on semantic to do it. This has been requested before and people have created some hack lisp, but with CEDET ever changing from 1.1 the code does not work.
===
PS: Latest edit: Out of no where the errors have gone away, the only thing I can remember doing is saving the buffer. You can tell when the errors have gone away because the global-decaration's start to show - i.e. the underlines and highlighted include files. Is this because I saved the buffer? I am unsure. I cannot recall if I was saving it before. Also, the file save of the DB has increased and the last modification of the DB file was a few minutes ago from this post:
What was before:
-rw-r--r-- 1 [USER] Administrators 449 Oct 8 13:42 !drive_d![SOME_STUFF]!semantic.cache
Is now:
-rw-r--r-- 1 [USER] Administrators 158327 Oct 8 15:38 !drive_d![SOME_STUFF]!semantic.cache

Having just messed about at work a lot of the glitches that I originally found are starting to make sense and are appearing to be just my lack of understanding of the product. There is no problem parsing system includes (such as STL) or local includes anymore on Windows and this is mainly down the the brilliant feature of: global-semantic-decoration-mode. It makes it clear if a source file has been parsed or not, etc etc. So now, I use this in my .emacs.
The problem of inconsistency (which I have found is not inconsistency, see below) - I have found - arises when the parser comes across a line of code like this:
#if defined(X)
//hundreds of lines of code
#endif /* define(X) */
I can half understand it. Unless X has been defined then don't bother parsing. But, I still want CEDET/Semantic to work on all of the code. I still might want to use completion if I am working in a function that exists in an area non-existent because of something undefined.
I say, naively, that semantic/cedet should parse code regardless of whether something is defined or not. However, perhaps this was a premeditated feature?
Thanks.

Related

Emacs being laggy and creating 0 byte files in working directory

I've Emacs setup for Verilog, SystemVerilog and UVM.
I use auto-complete, solarize theme and verilog-mode as add-ons.
I need to work on C once in a while, however with C Emacs feels very laggy (takes a while for auto-complete suggestions) and it creates bunch of 0 byte files in my working directory (with names containing symbols -- not letters).
I'm not sure about the cause or how to debug and solve the issue. I would appreciate if someone can help me with finding and solving this issue.
[EDIT]: I understand this can be lacking in information, however right now I'm not sure what type of information I should be providing, I will provide information as required
[EDIT2]:
I've commented following portion of init file and my c editing is working well, What part of loading auto-complete can cause these?
The problems I was facing:
1. Creating random symbol files with 0 bytes of size in working directory (name would look like ?/??UR...)
2. Laggy: takes a while for character to show up when typed
;; This section is required to enable autocomplete and verilog dictionary
;;(add-to-list 'load-path "/home/user/.emacs.d/")
;;(require 'auto-complete-config)
;;(add-to-list 'ac-dictionary-directories "/home/user/.emacs.d//ac-dict")
;;(ac-config-default)
;;ac-modes - mojor modes ac can run on
;;(add-to-list 'ac-modes 'verilog-mode 'c-mode)
;;toggle auto complete in all buffers
;;(global-auto-complete-mode t)
I understand this can be lacking in information, however right now I'm not sure what type of information I should be providing, I will provide information as required
That's the right attitude, and yes, you sensed correctly that the problem description is currently too broad for people to be able to help (unless you are lucky and find someone who recognizes the same combination of setups etc.).
The first step is to isolate the cause of the problem, at least to one (instead of 3) feature that you are using. IOW, break down your "setup for Verilog, SystemVerilog and UVM" which uses "auto-complete, solarize theme and verilog-mode as add-ons", so that you can report that the problem is only in using, say, auto-complete. Or is only in the combination of, say, theme solarize with verilog-mode.
IOW, at the highest level this is no different from any other debugging scenario.
As it stands now, you are, in effect, telling us that you have this big sack of stuff and you want someone to guess what is going on.
To narrow the problem, recursively bisect your init file, commenting out bigger and bigger chunks, until you know what part(s) of it are really causing the problem. Comment out 1/2, then 3/4, then 7/8,... You can use command comment-region to comment or (with prefix arg C-u) uncommment the selected text.
Once you have a better idea of what is causing the problem, report back here with the refined problem statement and the additional info you've learned.
At that point you will also want to specify what you mean by this or that being "laggy". You will hopefully be able to give others a recipe to reproduce the effect you see, and you will be able to describe better what you expected to see, but didn't.

Emacs 23 window.el

I am using emacs 23 on two computers.
On both, dpkg -s emacs outputs the following version number.
However one has window.el and the other not. This make some function such as split-window behave differently. The help page of this function on the computer that apparently has not window.el installed reads that it comes from C source code instead.
Where does this difference comes from?
I prefer the behaviour of the one that says that split-window comes from window.el: it allows to specify the SIDE when splitting window and provide additional function such as window-resize.
I suppose this is the most recent one but I do not know how to check it nor how to upgrade the other to this state.
Library window.el is as old as the hills. Perhaps you meant that one of your Emacs installlations has window.elc but not window.el?
More likely, you are referring only to function split-window. Yes, it used to be a built-in function (i.e., defined in C), and now it is defined in window.el (which file exists also for the older Emacs versions where that function is a built-in).
FYI, lots of window and buffer-display stuff was changed around the same time as split-window was rewritten in Lisp. Lots of behaviors changed, in minor or major ways.
What is not at all clear is what the problem is that you are reporting. You ask, "Where does this difference comes from? How to fix it?" I've explained a bit about the difference. As for how to fix it -- what is the "it" that needs fixing, and what would the fixed behavior be like?
IOW, your question is, so far, unanswerable. If you specify things more exactly, perhaps we can help more.
I'm not certain what's going on with your debian packages, but if memory serves the readable .el(.gz) files are not supplied in the basic package, but in a separate package. This is because all you strictly need is the byte-compiled .elc files, so they can reduce the base package filesize by omitting them (at the expense of enabling you to read the elisp code).
Is M-x load-library RET window RET successful?
Note that Emacs 24 is the current stable version. You might want to upgrade.
Edit:
M-x emacs-version tells you which version of Emacs you're running, which will always give you a definitive answer.
(And if the versions are identical, then run emacs -Q to eliminate and site- and user-specific config files from the picture, as those are always a likely culprit for differing behaviours.)

emacs Semantic/senator : autocomplete for external lib's

It seems this forum is more alive than mailing list : http://sourceforge.net/mailarchive/forum.php?forum_name=cedet-semantic.
I would like repost my quest from a week ago from there:
First hi to all who contribute to this great package as CEDET :D .
Without much hussle I am able to get working most of the CEDET futures, but when it comes to senator / semantic things get more tought :\ .
Parsing local files are fine.
I don't use EDE not to get things more complicated.
I use the 1.0.6 git trunk version, for compability with ECB.
First is the rumble about the emacs core / cedet git-trunk hussle. How do I check that current installation is running the latter ? ( I have done some .emacs modificaitons see below) .
I generally cannot get the proper autocomplete working for external libs - in this case the OGRE3D project, which all are in the /usr/include/OGRE. I suppose I have added to 'search path' include properly, semantic-describe-c-env. sees them added properly.
2.a What are the basic commands to the semantic parser ? , that is I need to force it to parse the desired includes.
Once I saw semantic parsing the OGRE files in the 'idle time'. Still the autocomplete does not work ( OGRE:RAY is not recongized as a type).
senator-completition-menu-pop gives some non-matching 'c**p'
2.b I know there are customize-group options for semantic, tough their description say little to me.
From the other post:
"Yes, there is a setup cost. You can use semanticdb.sh to pre-parse your
code, but if you never open every file, you might end up with Emacs
having such a huge data structure it gets larger that your machine can
handle. If your project is small, this shouldn't be a problem."
Well this might be, if that would parse OGRE.
here's my .emacs:
.emacs at pastebin.com
Here's what I got on the mailing list, hope that it would help someone , thaks to Eric Ludlam :D :
======================
1. First is the rumble about the emacs core / cedet git-trunk hussle. How do I check that current installation is running the latter ? ( I have done some .emacs modificaitons see below) .
After emacs start, use:
M-x cedet-version RET
and look for the 1.1 version from CEDET/bzr.
I just tried this and noticed not everything has the right version
number. Interesting. I'll have to look into that.
Anyway, the next thing to try is:
M-x locate-library RET cedet RET
and make sure it points where you think it should.
2. I generally cannot get the proper autocomplete working for external libs - in this case the OGRE3D project, which all are in the /usr/include/OGRE. I suppose I have added to 'search path' include properly, semantic-describe-c-env. sees them added properly.
If you enable global-semantic-decoration-mode you can right-click on
header files, and it will give you some options, such as showing where
it things the header is, and showing if it has been parsed yet or not.
2.a What are the basic commands to the semantic parser ? , that is I need to force it to parse the desired includes.
You can use the include menu to force a header to be parsed, or visit
said include. If it can't find it, you can add OGRE to your path from
there too.
If you vist your header, you can use the senator menu to force a file to
reparse, or use:
C-u M-x bovinate RET
to do it.
Once I saw semantic parsing the OGRE files in the 'idle time'. Still the autocomplete does not work ( OGRE:RAY is not recongized as a type). senator-completition-menu-pop gives some non-matching 'c**p'
Autocomplete can fail for many reasons. The best way to find out why is:
M-x semantic-analyze-debug-assist RET
at a place you want to do completion. It will tell you about your
header files, symbols, and the like. It could be your preprocessor
symbols need some setup.
For large complex library headers, sometimes it is just a matter of
having the right pre-processor symbols setup in Semantic so that the
right bits of the headers get parsed for symbols. You'd have to visit a
header where a symbol you want to complete is, and see if it was parsed.
Using:
M-x boviante RET
will dump the symbol table.
2.b I know there are customize-group options for semantic, tough their description say little to me.
From the other post:
"Yes, there is a setup cost. You can use semanticdb.sh to pre-parse your code, but if you never open *every* file, you might end up with Emacs having such a huge data structure it gets larger that your machine can handle. If your project is small, this shouldn't be a problem." Well this might be, if that would parse OGRE.
I doubt parsing the includes is the problem here. I think there is just
something new in the ogre headers we'll have to deal with.
Eric
===================================

Is there a way to write a .emacs that will always stay upward compatible?

I have been using Emacs since version 18. Emacs Lisp isn't my routine programming language, but years ago I invested some time studying it to the point of creating a .emacs that's better (for me) than any GUI IDE to date.
That was a one-time effort and since then, I forgot completely how to program in lisp.
Alas, every time I upgrade my Emacs (18 > 19 > 20 > 21 > 22 > 23), something in my .emacs breaks, and I end up spending way too many hours (sometimes days) fixing these.
In many other languages I program routinely, it is possible to write code that never becomes obsolete. In emacs, on the other hand, I can never predict how things will change. For example [M-TAB] that used to work up until version 21.4.1, no longer works in version 23 and must be replaced with "\M-\t". Another example is dired-omit-toggle that used to work in version 21 but stopped working in version 22, being replaced by dired-omit-mode.
Now, I know that if a .emacs doesn't do much, it's possible to write "an almost empty" .emacs that can (probably) stay compatible with future versions.
But my .emacs is huge, designed to run on many different operating systems (and their different flavors, editions and versions, including non-GUI systems) without a single change. I wish there was a core-API or subset that is guaranteed to always work.
Is there really such a way to write a .emacs that will always stay upward compatible?
If so, where can I find a "cook book" or authoritative guidelines for accomplishing this?
Use (when (boundp 'some-variable) …) or (when (fboundp 'some-function) …) around any piece of code that relies on a specific feature. (While you're at it, start with (require 'cl) for those older versions that don't have when built-in.)
When all else fails, discriminate on emacs-major-version, emacs-minor-version and running-xemacs (defined as (string-match "XEmacs\\|Lucid" emacs-version)).
Avoid syntax and library functions that are only supported in newer versions.
It's rare that something breaks when you stick to documented interfaces. So try to look for a way to do things that's mentioned in the manual, and only fall back to modifying some random non-customizable variable if you see no other way. In my experience there is always a reasonably easy way to get something to work in all versions (at least with GNU Emacs, XEmacs is sometimes harder to please) if you allow the occasional conditional.
For example, "\e\t" has always worked for M-TAB. With dired-omit-mode, fall back to dired-omit-toggle if the former does not exist:
(set (if boundp 'dired-omit-mode 'dired-omit-mode 'dired-omit-toggle) t)
Yes, it's slightly painful, but not as dramatic as you make it out to be. I maintain a .emacs that works with anything since 19.23 (IIRC, it's been a while since I tested with anything older than 19.34) on all of DOS, Windows and unix. Compatibility with Windows is in fact more of a burden than keeping up with GNU Emacs version changes.
As for a cookbook, well, most differences between versions have to do with features that aren't very widely used (otherwise the maintainers would give more importance to strict upward compatibility). Since Emacs is big, there's undoubtedly plenty of it that you use but the cookbook writer wouldn't have heard of. You'll have to play it by ear. Fortunately it's not too hard.
Since Its impossible to predict future changes of anything, no one can guarantee the future compatibility.
I think the following points are few of many general ways to make it easy to maintain .emacs or init.el (which I am practicing right now.)
put .emacs.d/ version control (MUST one)
split init file into several small files.
use when to load specific customizations for a version of emacs.
for eg:
(when (= emacs-major-version 24)
;;load my settings for 24
)
I sympathize, and I share your pain. The answer is no, there is no such holy grail, I'm afraid. As you said, if your init file is simple enough then you might not need to change anything. Actually, even that's not true: the init file name and where Emacs looks for it have both changed over time.

How to customize dired's display

How do I make Dired display its files using an arbitrary function or set of columns? Basically I want to change from:
-rw-r--r-- 1 konrad konrad 3847863 Out 18 14:17 ClojureinAction.pdf
-rw-rw-r-- 1 tamara tamara 27338341 Out 20 07:16 Halliday, Resnick, Walker - Fundamentals of Physics.pdf
-rw-r--r-- 1 konrad konrad 3921024 Set 22 11:11 Pragmatic.Programming.Clojure.May.2009.pdf
To something like
644 1-5MB ClojureinAction.pdf PDF (5 days ago, 400pgs)
664 10-100MB Halliday, Resnic...pdf PDF (3 days ago, 1000pgs, Tamara's)
644 1-5MB Pragmatic.Progra...pdf PDF (1 min ago, 100 pages)
Thanks!
EDIT: Thanks for the answer, Gareth, but could you be more verbose, please? Apparently the hook will just allow me to run arbitrary code when the buffer loads up. Dired won't even stop loading up the buffer :(
(defun foo (&rest args) (unlocking-buffer (message "foo") (insert "foo\n")))
Glancing at dired's source code, it seems that it gets information from these very formats I'm trying to replace, so I wonder if it's viable to change it this way, or if I'll end up having to rewrite everything.
Dired mode makes quite a few assumptions about ls output format, so changing the format will break many things. I think a more feasible approach is to leave the format alone, and use either text-properties or overlays to change the presentation.
This isn't nearly as drastic as what you're looking for, but it is possible to customize how Emacs calls ls in dired-mode.
M-x customize-variable RET dired-listing-switches RET
I used it to omit the group ID of files with the -o option, saving some horizontal screen real estate.
Write a function that transforms the output of ls into the format you want, and then add that function to dired-after-readin-hook.
Edited to add: dired-mode determines the name of the file by parsing the output of ls, so some features of dired will break when you change the format. You can make (some of) them work again by changing directory-listing-before-filename-regexp and dired-permission-flags-regexp. Since your change to the format is quite radical, you may prefer to rewrite the functions dired-move-to-filename and dired-move-to-end-of-filename.
(This sounds tough but it's not impossible. I customize the format of dired buffers in the manner I described, though not nearly so radically as you propose to do.)
You will have a lot of work if you insist on truncating the filename, because dired-mode assumes that it can get the filename on the current line by calling
(buffer-substring (dired-move-to-filename) (dired-move-to-end-of-filename))
I'd use the answer here: https://stackoverflow.com/a/1796009/714357
and the 'compile command which will run in your default-directory. So it will give you a new buffer, but it is the information you are looking for.
(defun my/ls-mode-numbers ()
(interactive)
(compile " ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) \
*2^(8-i));if(k)printf(\"%0o \",k);print}'"))