Perform scope autocompletion based on function return types
[geany-mirror.git] / src / sciwrappers.c
blob34fa60cb1fb11decafd72042c3eed1c434ab6979
1 /*
2 * sciwrappers.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 /** @file sciwrappers.h
23 * Wrapper functions for the Scintilla editor widget @c SCI_* messages.
24 * You should also check the http://scintilla.org documentation, as it is more detailed.
26 * To get Scintilla notifications, use the
27 * @link pluginsignals.c @c "editor-notify" signal @endlink.
29 * @note These functions were originally from the cssed project
30 * (http://cssed.sf.net, thanks).
31 * @see scintilla_send_message().
34 #ifdef HAVE_CONFIG_H
35 # include "config.h"
36 #endif
38 #include "sciwrappers.h"
40 #include "utils.h"
42 #include <string.h>
45 #define SSM(s, m, w, l) scintilla_send_message(s, m, w, l)
48 /* line numbers visibility */
49 void sci_set_line_numbers(ScintillaObject *sci, gboolean set)
51 if (set)
53 gchar tmp_str[15];
54 gint len = (gint) SSM(sci, SCI_GETLINECOUNT, 0, 0);
55 gint width;
57 g_snprintf(tmp_str, 15, "_%d", len);
58 width = sci_text_width(sci, STYLE_LINENUMBER, tmp_str);
59 SSM(sci, SCI_SETMARGINWIDTHN, 0, width);
60 SSM(sci, SCI_SETMARGINSENSITIVEN, 0, FALSE); /* use default behaviour */
62 else
64 SSM(sci, SCI_SETMARGINWIDTHN, 0, 0);
69 void sci_set_mark_long_lines(ScintillaObject *sci, gint type, gint column, const gchar *colour)
71 glong colour_val = utils_parse_color_to_bgr(colour); /* Scintilla uses a "long" value */
73 if (column == 0)
74 type = 2;
75 switch (type)
77 case 0:
79 SSM(sci, SCI_SETEDGEMODE, EDGE_LINE, 0);
80 break;
82 case 1:
84 SSM(sci, SCI_SETEDGEMODE, EDGE_BACKGROUND, 0);
85 break;
87 case 2:
89 SSM(sci, SCI_SETEDGEMODE, EDGE_NONE, 0);
90 return;
93 SSM(sci, SCI_SETEDGECOLUMN, (uptr_t) column, 0);
94 SSM(sci, SCI_SETEDGECOLOUR, (uptr_t) colour_val, 0);
98 /* symbol margin visibility */
99 void sci_set_symbol_margin(ScintillaObject *sci, gboolean set)
101 if (set)
103 SSM(sci, SCI_SETMARGINWIDTHN, 1, 16);
104 SSM(sci, SCI_SETMARGINSENSITIVEN, 1, TRUE);
106 else
108 SSM(sci, SCI_SETMARGINWIDTHN, 1, 0);
109 SSM(sci, SCI_SETMARGINSENSITIVEN, 1, FALSE);
114 /* folding margin visibility */
115 void sci_set_folding_margin_visible(ScintillaObject *sci, gboolean set)
117 if (set)
119 SSM(sci, SCI_SETMARGINWIDTHN, 2, 12);
120 SSM(sci, SCI_SETMARGINSENSITIVEN, 2, TRUE);
122 else
124 SSM(sci, SCI_SETMARGINSENSITIVEN, 2, FALSE);
125 SSM(sci, SCI_SETMARGINWIDTHN, 2, 0);
130 /* end of lines */
131 void sci_set_visible_eols(ScintillaObject *sci, gboolean set)
133 SSM(sci, SCI_SETVIEWEOL, set != FALSE, 0);
137 void sci_set_visible_white_spaces(ScintillaObject *sci, gboolean set)
139 if (set)
140 SSM(sci, SCI_SETVIEWWS, SCWS_VISIBLEALWAYS, 0);
141 else
142 SSM(sci, SCI_SETVIEWWS, SCWS_INVISIBLE, 0);
146 void sci_set_lines_wrapped(ScintillaObject *sci, gboolean set)
148 if (set)
149 SSM(sci, SCI_SETWRAPMODE, SC_WRAP_WORD, 0);
150 else
151 SSM(sci, SCI_SETWRAPMODE, SC_WRAP_NONE, 0);
155 gint sci_get_eol_mode(ScintillaObject *sci)
157 return (gint) SSM(sci, SCI_GETEOLMODE, 0, 0);
161 void sci_set_eol_mode(ScintillaObject *sci, gint eolmode)
163 SSM(sci, SCI_SETEOLMODE, (uptr_t) eolmode, 0);
167 void sci_convert_eols(ScintillaObject *sci, gint eolmode)
169 SSM(sci, SCI_CONVERTEOLS, (uptr_t) eolmode, 0);
173 void sci_add_text(ScintillaObject *sci, const gchar *text)
175 if (text != NULL)
176 { /* if null text is passed scintilla will segfault */
177 SSM(sci, SCI_ADDTEXT, strlen(text), (sptr_t) text);
182 /** Sets all text.
183 * @param sci Scintilla widget.
184 * @param text Text. */
185 GEANY_API_SYMBOL
186 void sci_set_text(ScintillaObject *sci, const gchar *text)
188 if( text != NULL ){ /* if null text is passed to scintilla will segfault */
189 SSM(sci, SCI_SETTEXT, 0, (sptr_t) text);
194 gboolean sci_can_undo(ScintillaObject *sci)
196 return SSM(sci, SCI_CANUNDO, 0, 0) != FALSE;
200 gboolean sci_can_redo(ScintillaObject *sci)
202 return SSM(sci, SCI_CANREDO, 0, 0) != FALSE;
206 void sci_undo(ScintillaObject *sci)
208 if (sci_can_undo(sci))
209 SSM(sci, SCI_UNDO, 0, 0);
213 void sci_redo(ScintillaObject *sci)
215 if (sci_can_redo(sci))
216 SSM(sci, SCI_REDO, 0, 0);
220 /** Begins grouping a set of edits together as one Undo action.
221 * You must call sci_end_undo_action() after making your edits.
222 * @param sci Scintilla @c GtkWidget. */
223 GEANY_API_SYMBOL
224 void sci_start_undo_action(ScintillaObject *sci)
226 SSM(sci, SCI_BEGINUNDOACTION, 0, 0);
230 /** Ends grouping a set of edits together as one Undo action.
231 * @param sci Scintilla @c GtkWidget.
232 * @see sci_start_undo_action(). */
233 GEANY_API_SYMBOL
234 void sci_end_undo_action(ScintillaObject *sci)
236 SSM(sci, SCI_ENDUNDOACTION, 0, 0);
240 void sci_set_undo_collection(ScintillaObject *sci, gboolean set)
242 SSM(sci, SCI_SETUNDOCOLLECTION, set != FALSE, 0);
246 void sci_empty_undo_buffer(ScintillaObject *sci)
248 SSM(sci, SCI_EMPTYUNDOBUFFER, 0, 0);
252 gboolean sci_is_modified(ScintillaObject *sci)
254 return (SSM(sci, SCI_GETMODIFY, 0, 0) != 0);
258 void sci_zoom_in(ScintillaObject *sci)
260 SSM(sci, SCI_ZOOMIN, 0, 0);
264 void sci_zoom_out(ScintillaObject *sci)
266 SSM(sci, SCI_ZOOMOUT, 0, 0);
270 void sci_zoom_off(ScintillaObject *sci)
272 SSM(sci, SCI_SETZOOM, 0, 0);
276 /** Sets a line marker.
277 * @param sci Scintilla widget.
278 * @param line_number Line number.
279 * @param marker Marker number. */
280 GEANY_API_SYMBOL
281 void sci_set_marker_at_line(ScintillaObject *sci, gint line_number, gint marker)
283 SSM(sci, SCI_MARKERADD, (uptr_t) line_number, marker);
287 /** Deletes a line marker.
288 * @param sci Scintilla widget.
289 * @param line_number Line number.
290 * @param marker Marker number. */
291 GEANY_API_SYMBOL
292 void sci_delete_marker_at_line(ScintillaObject *sci, gint line_number, gint marker)
294 SSM(sci, SCI_MARKERDELETE, (uptr_t) line_number, marker);
298 /** Checks if a line has a marker set.
299 * @param sci Scintilla widget.
300 * @param line Line number.
301 * @param marker Marker number.
302 * @return Whether it's set. */
303 GEANY_API_SYMBOL
304 gboolean sci_is_marker_set_at_line(ScintillaObject *sci, gint line, gint marker)
306 gint state;
308 state = (gint) SSM(sci, SCI_MARKERGET, (uptr_t) line, 0);
309 return (state & (1 << marker));
313 void sci_toggle_marker_at_line(ScintillaObject *sci, gint line, gint marker)
315 gboolean set = sci_is_marker_set_at_line(sci, line, marker);
317 if (!set)
318 sci_set_marker_at_line(sci, line, marker);
319 else
320 sci_delete_marker_at_line(sci, line, marker);
324 /* Returns the line number of the next marker that matches marker_mask, or -1.
325 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
326 * Note: If there is a marker on the line, it returns the same line. */
327 gint sci_marker_next(ScintillaObject *sci, gint line, gint marker_mask, gboolean wrap)
329 gint marker_line;
331 marker_line = (gint) SSM(sci, SCI_MARKERNEXT, (uptr_t) line, marker_mask);
332 if (wrap && marker_line == -1)
333 marker_line = (gint) SSM(sci, SCI_MARKERNEXT, 0, marker_mask);
334 return marker_line;
338 /* Returns the line number of the previous marker that matches marker_mask, or -1.
339 * marker_mask is a bitor of 1 << marker_index. (See MarkerHandleSet::MarkValue()).
340 * Note: If there is a marker on the line, it returns the same line. */
341 gint sci_marker_previous(ScintillaObject *sci, gint line, gint marker_mask, gboolean wrap)
343 gint marker_line;
345 marker_line = (gint) SSM(sci, SCI_MARKERPREVIOUS, (uptr_t) line, marker_mask);
346 if (wrap && marker_line == -1)
348 gint len = sci_get_length(sci);
349 gint last_line = sci_get_line_from_position(sci, len - 1);
351 marker_line = (gint) SSM(sci, SCI_MARKERPREVIOUS, (uptr_t) last_line, marker_mask);
353 return marker_line;
357 /** Gets the line number from @a position.
358 * @param sci Scintilla widget.
359 * @param position Position.
360 * @return The line. */
361 GEANY_API_SYMBOL
362 gint sci_get_line_from_position(ScintillaObject *sci, gint position)
364 return (gint) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) position, 0);
368 /** Gets the column number relative to the start of the line that @a position is on.
369 * @param sci Scintilla widget.
370 * @param position Position.
371 * @return The column. */
372 GEANY_API_SYMBOL
373 gint sci_get_col_from_position(ScintillaObject *sci, gint position)
375 return (gint) SSM(sci, SCI_GETCOLUMN, (uptr_t) position, 0);
379 gint sci_get_position_from_col(ScintillaObject *sci, gint line, gint col)
381 return (gint) SSM(sci, SCI_FINDCOLUMN, line, col);
385 /** Gets the position for the start of @a line.
386 * @param sci Scintilla widget.
387 * @param line Line.
388 * @return Position. */
389 GEANY_API_SYMBOL
390 gint sci_get_position_from_line(ScintillaObject *sci, gint line)
392 return (gint) SSM(sci, SCI_POSITIONFROMLINE, (uptr_t) line, 0);
396 /** Gets the cursor position.
397 * @param sci Scintilla widget.
398 * @return Position. */
399 GEANY_API_SYMBOL
400 gint sci_get_current_position(ScintillaObject *sci)
402 return (gint) SSM(sci, SCI_GETCURRENTPOS, 0, 0);
406 gint sci_get_cursor_virtual_space(ScintillaObject *sci)
408 gint selection_mode = sci_get_selection_mode(sci);
410 return selection_mode == SC_SEL_RECTANGLE || selection_mode == SC_SEL_THIN ?
411 SSM(sci, SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE, 0, 0) :
412 SSM(sci, SCI_GETSELECTIONNCARETVIRTUALSPACE,
413 SSM(sci, SCI_GETMAINSELECTION, 0, 0), 0);
417 /** Sets the cursor position.
418 * @param sci Scintilla widget.
419 * @param position Position.
420 * @param scroll_to_caret Whether to scroll the cursor in view. */
421 GEANY_API_SYMBOL
422 void sci_set_current_position(ScintillaObject *sci, gint position, gboolean scroll_to_caret)
424 if (scroll_to_caret)
425 SSM(sci, SCI_GOTOPOS, (uptr_t) position, 0);
426 else
428 SSM(sci, SCI_SETCURRENTPOS, (uptr_t) position, 0);
429 SSM(sci, SCI_SETANCHOR, (uptr_t) position, 0); /* to avoid creation of a selection */
431 SSM(sci, SCI_CHOOSECARETX, 0, 0);
435 /* Set the cursor line without scrolling the view.
436 * Use sci_goto_line() to also scroll. */
437 void sci_set_current_line(ScintillaObject *sci, gint line)
439 gint pos = sci_get_position_from_line(sci, line);
440 sci_set_current_position(sci, pos, FALSE);
444 /** Gets the total number of lines.
445 * @param sci Scintilla widget.
446 * @return The line count. */
447 GEANY_API_SYMBOL
448 gint sci_get_line_count(ScintillaObject *sci)
450 return (gint) SSM(sci, SCI_GETLINECOUNT, 0, 0);
454 /** Sets the selection start position.
455 * @param sci Scintilla widget.
456 * @param position Position. */
457 GEANY_API_SYMBOL
458 void sci_set_selection_start(ScintillaObject *sci, gint position)
460 SSM(sci, SCI_SETSELECTIONSTART, (uptr_t) position, 0);
464 /** Sets the selection end position.
465 * @param sci Scintilla widget.
466 * @param position Position. */
467 GEANY_API_SYMBOL
468 void sci_set_selection_end(ScintillaObject *sci, gint position)
470 SSM(sci, SCI_SETSELECTIONEND, (uptr_t) position, 0);
474 void sci_set_selection(ScintillaObject *sci, gint anchorPos, gint currentPos)
476 SSM(sci, SCI_SETSEL, (uptr_t) anchorPos, currentPos);
480 /** Gets the position at the end of a line
481 * @param sci Scintilla widget.
482 * @param line Line.
483 * @return The position at the end of the line. */
484 GEANY_API_SYMBOL
485 gint sci_get_line_end_position(ScintillaObject *sci, gint line)
487 return (gint) SSM(sci, SCI_GETLINEENDPOSITION, (uptr_t) line, 0);
491 void sci_cut(ScintillaObject *sci)
493 SSM(sci, SCI_CUT, 0, 0);
497 void sci_copy(ScintillaObject *sci)
499 SSM(sci, SCI_COPY, 0, 0);
503 void sci_paste(ScintillaObject *sci)
505 SSM(sci, SCI_PASTE, 0, 0);
509 void sci_clear(ScintillaObject *sci)
511 SSM(sci, SCI_CLEAR, 0, 0);
515 /** Gets the selection start position.
516 * @param sci Scintilla widget.
517 * @return Position. */
518 GEANY_API_SYMBOL
519 gint sci_get_selection_start(ScintillaObject *sci)
521 return (gint) SSM(sci, SCI_GETSELECTIONSTART, 0, 0);
525 /** Gets the selection end position.
526 * @param sci Scintilla widget.
527 * @return Position. */
528 GEANY_API_SYMBOL
529 gint sci_get_selection_end(ScintillaObject *sci)
531 return (gint) SSM(sci, SCI_GETSELECTIONEND, 0, 0);
535 /** Replaces selection.
536 * @param sci Scintilla widget.
537 * @param text Text. */
538 GEANY_API_SYMBOL
539 void sci_replace_sel(ScintillaObject *sci, const gchar *text)
541 SSM(sci, SCI_REPLACESEL, 0, (sptr_t) text);
545 /** Gets the length of all text.
546 * @param sci Scintilla widget.
547 * @return Length. */
548 GEANY_API_SYMBOL
549 gint sci_get_length(ScintillaObject *sci)
551 return (gint) SSM(sci, SCI_GETLENGTH, 0, 0);
555 /** Gets the currently used lexer
556 * @param sci Scintilla widget.
557 * @returns The lexer ID
559 GEANY_API_SYMBOL
560 gint sci_get_lexer(ScintillaObject *sci)
562 return (gint) SSM(sci, SCI_GETLEXER, 0, 0);
566 void sci_set_lexer(ScintillaObject *sci, guint lexer_id)
568 gint old = sci_get_lexer(sci);
570 SSM(sci, SCI_SETLEXER, lexer_id, 0);
572 if (old != (gint)lexer_id)
573 SSM(sci, SCI_CLEARDOCUMENTSTYLE, 0, 0);
577 /** Gets line length.
578 * @param sci Scintilla widget.
579 * @param line Line number.
580 * @return Length. */
581 GEANY_API_SYMBOL
582 gint sci_get_line_length(ScintillaObject *sci, gint line)
584 return (gint) SSM(sci, SCI_LINELENGTH, (uptr_t) line, 0);
588 /* safe way to read Scintilla string into new memory.
589 * works with any string buffer messages that follow the Windows message convention. */
590 gchar *sci_get_string(ScintillaObject *sci, guint msg, gulong wParam)
592 gint size = (gint) SSM(sci, msg, wParam, 0);
593 gchar *str = g_malloc(size + 1);
595 SSM(sci, msg, wParam, (sptr_t) str);
596 str[size] = '\0'; /* ensure termination, needed for SCI_GETLINE */
597 return str;
601 /** Gets line contents.
602 * @param sci Scintilla widget.
603 * @param line_num Line number.
604 * @return A @c NULL-terminated copy of the line text. */
605 GEANY_API_SYMBOL
606 gchar *sci_get_line(ScintillaObject *sci, gint line_num)
608 return sci_get_string(sci, SCI_GETLINE, (gulong) line_num);
612 /** Gets all text.
613 * @deprecated sci_get_text is deprecated and should not be used in newly-written code.
614 * Use sci_get_contents() instead.
616 * @param sci Scintilla widget.
617 * @param len Length of @a text buffer, usually sci_get_length() + 1.
618 * @param text Text buffer; must be allocated @a len + 1 bytes for null-termination. */
619 GEANY_API_SYMBOL
620 void sci_get_text(ScintillaObject *sci, gint len, gchar *text)
622 SSM(sci, SCI_GETTEXT, (uptr_t) len, (sptr_t) text);
626 /** Allocates and fills a buffer with text from the start of the document.
627 * @param sci Scintilla widget.
628 * @param buffer_len Buffer length to allocate, including the terminating
629 * null char, e.g. sci_get_length() + 1. Alternatively use @c -1 to get all
630 * text (since Geany 1.23).
631 * @return A copy of the text. Should be freed when no longer needed.
633 * @since 1.23 (0.17)
635 GEANY_API_SYMBOL
636 gchar *sci_get_contents(ScintillaObject *sci, gint buffer_len)
638 gchar *text;
640 if (buffer_len < 0)
641 buffer_len = sci_get_length(sci) + 1;
643 text = g_malloc(buffer_len);
644 SSM(sci, SCI_GETTEXT, (uptr_t) buffer_len, (sptr_t) text);
645 return text;
649 /** Gets selected text.
650 * @deprecated sci_get_selected_text is deprecated and should not be used in newly-written code.
651 * Use sci_get_selection_contents() instead.
653 * @param sci Scintilla widget.
654 * @param text Text buffer; must be allocated sci_get_selected_text_length() + 1 bytes
655 * for null-termination. */
656 GEANY_API_SYMBOL
657 void sci_get_selected_text(ScintillaObject *sci, gchar *text)
659 SSM(sci, SCI_GETSELTEXT, 0, (sptr_t) text);
663 /** Gets selected text.
664 * @param sci Scintilla widget.
666 * @return The selected text. Should be freed when no longer needed.
668 * @since 0.17
670 GEANY_API_SYMBOL
671 gchar *sci_get_selection_contents(ScintillaObject *sci)
673 return sci_get_string(sci, SCI_GETSELTEXT, 0);
677 /** Gets selected text length.
678 * @param sci Scintilla widget.
679 * @return Length. */
680 GEANY_API_SYMBOL
681 gint sci_get_selected_text_length(ScintillaObject *sci)
683 return (gint) SSM(sci, SCI_GETSELTEXT, 0, 0);
687 gint sci_get_position_from_xy(ScintillaObject *sci, gint x, gint y, gboolean nearby)
689 /* for nearby return -1 if there is no character near to the x,y point. */
690 return (gint) SSM(sci, (nearby) ? SCI_POSITIONFROMPOINTCLOSE : SCI_POSITIONFROMPOINT, (uptr_t) x, y);
694 /** Checks if a line is visible (folding may have hidden it).
695 * @param sci Scintilla widget.
696 * @param line Line number.
697 * @return Whether @a line will be drawn on the screen. */
698 GEANY_API_SYMBOL
699 gboolean sci_get_line_is_visible(ScintillaObject *sci, gint line)
701 return SSM(sci, SCI_GETLINEVISIBLE, (uptr_t) line, 0) != FALSE;
705 /** Makes @a line visible (folding may have hidden it).
706 * @param sci Scintilla widget.
707 * @param line Line number. */
708 GEANY_API_SYMBOL
709 void sci_ensure_line_is_visible(ScintillaObject *sci, gint line)
711 SSM(sci, SCI_ENSUREVISIBLE, (uptr_t) line, 0);
715 gint sci_get_fold_level(ScintillaObject *sci, gint line)
717 return (gint) SSM(sci, SCI_GETFOLDLEVEL, (uptr_t) line, 0);
721 /* Get the line number of the fold point before start_line, or -1 if there isn't one */
722 gint sci_get_fold_parent(ScintillaObject *sci, gint start_line)
724 return (gint) SSM(sci, SCI_GETFOLDPARENT, (uptr_t) start_line, 0);
728 void sci_toggle_fold(ScintillaObject *sci, gint line)
730 SSM(sci, SCI_TOGGLEFOLD, (uptr_t) line, 0);
734 gboolean sci_get_fold_expanded(ScintillaObject *sci, gint line)
736 return SSM(sci, SCI_GETFOLDEXPANDED, (uptr_t) line, 0) != FALSE;
740 void sci_colourise(ScintillaObject *sci, gint start, gint end)
742 SSM(sci, SCI_COLOURISE, (uptr_t) start, end);
746 void sci_clear_all(ScintillaObject *sci)
748 SSM(sci, SCI_CLEARALL, 0, 0);
752 gint sci_get_end_styled(ScintillaObject *sci)
754 return (gint) SSM(sci, SCI_GETENDSTYLED, 0, 0);
758 void sci_set_tab_width(ScintillaObject *sci, gint width)
760 SSM(sci, SCI_SETTABWIDTH, (uptr_t) width, 0);
764 /** Gets display tab width (this is not indent width, see GeanyIndentPrefs).
765 * @param sci Scintilla widget.
766 * @return Width.
768 * @since 0.15
770 GEANY_API_SYMBOL
771 gint sci_get_tab_width(ScintillaObject *sci)
773 return (gint) SSM(sci, SCI_GETTABWIDTH, 0, 0);
777 /** Gets a character.
778 * @param sci Scintilla widget.
779 * @param pos Position.
780 * @return Char. */
781 GEANY_API_SYMBOL
782 gchar sci_get_char_at(ScintillaObject *sci, gint pos)
784 return (gchar) SSM(sci, SCI_GETCHARAT, (uptr_t) pos, 0);
788 void sci_set_savepoint(ScintillaObject *sci)
790 SSM(sci, SCI_SETSAVEPOINT, 0, 0);
794 void sci_set_indentation_guides(ScintillaObject *sci, gint mode)
796 SSM(sci, SCI_SETINDENTATIONGUIDES, (uptr_t) mode, 0);
800 void sci_use_popup(ScintillaObject *sci, gboolean enable)
802 SSM(sci, SCI_USEPOPUP, enable != FALSE, 0);
806 /** Checks if there's a selection.
807 * @param sci Scintilla widget.
808 * @return Whether a selection is present.
810 * @since 0.15
812 GEANY_API_SYMBOL
813 gboolean sci_has_selection(ScintillaObject *sci)
815 if (SSM(sci, SCI_GETSELECTIONEND, 0, 0) - SSM(sci, SCI_GETSELECTIONSTART, 0, 0))
816 return TRUE;
817 else
818 return FALSE;
822 void sci_goto_pos(ScintillaObject *sci, gint pos, gboolean unfold)
824 if (unfold) SSM(sci, SCI_ENSUREVISIBLE, (uptr_t) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) pos, 0), 0);
825 SSM(sci, SCI_GOTOPOS, (uptr_t) pos, 0);
829 void sci_set_search_anchor(ScintillaObject *sci)
831 SSM(sci, SCI_SEARCHANCHOR, 0, 0);
835 /* removes a selection if pos < 0 */
836 void sci_set_anchor(ScintillaObject *sci, gint pos)
838 if (pos < 0)
839 pos = sci_get_current_position(sci);
841 SSM(sci, SCI_SETANCHOR, (uptr_t) pos, 0);
845 /** Scrolls the cursor in view.
846 * @param sci Scintilla widget. */
847 GEANY_API_SYMBOL
848 void sci_scroll_caret(ScintillaObject *sci)
850 SSM(sci, SCI_SCROLLCARET, 0, 0);
854 void sci_scroll_columns(ScintillaObject *sci, gint columns)
856 SSM(sci, SCI_LINESCROLL, (uptr_t) columns, 0);
860 gint sci_search_next(ScintillaObject *sci, gint flags, const gchar *text)
862 /* FIXME: SCI_SEACHNEXT() actually returns long */
863 return (gint) SSM(sci, SCI_SEARCHNEXT, (uptr_t) flags, (sptr_t) text);
867 gint sci_search_prev(ScintillaObject *sci, gint flags, const gchar *text)
869 /* FIXME: SCI_SEACHPREV() actually returns long */
870 return (gint) SSM(sci, SCI_SEARCHPREV, (uptr_t) flags, (sptr_t) text);
874 /** Finds text in the document.
875 * The @a ttf argument should be a pointer to a Sci_TextToFind structure which contains
876 * the text to find and the range in which the text should be searched.
878 * Please refer to the Scintilla documentation for a more detailed description.
880 * @param sci Scintilla widget.
881 * @param flags Bitmask of Scintilla search flags (@c SCFIND_*, see Scintilla documentation).
882 * @param ttf Pointer to a TextToFind structure which contains the text to find and the range.
883 * @return The position of the start of the found text if it succeeds, otherwise @c -1.
884 * The @c chrgText.cpMin and @c chrgText.cpMax members of @c TextToFind are filled in
885 * with the start and end positions of the found text.
887 GEANY_API_SYMBOL
888 gint sci_find_text(ScintillaObject *sci, gint flags, struct Sci_TextToFind *ttf)
890 return (gint) SSM(sci, SCI_FINDTEXT, (uptr_t) flags, (sptr_t) ttf);
894 /** Sets the font for a particular style.
895 * @param sci Scintilla widget.
896 * @param style The style.
897 * @param font The font name.
898 * @param size The font size. */
899 GEANY_API_SYMBOL
900 void sci_set_font(ScintillaObject *sci, gint style, const gchar *font, gint size)
902 SSM(sci, SCI_STYLESETFONT, (uptr_t) style, (sptr_t) font);
903 SSM(sci, SCI_STYLESETSIZE, (uptr_t) style, size);
907 /** Jumps to the specified line in the document.
908 * If @a unfold is set and @a line is hidden by a fold, it is unfolded
909 * first to ensure it is visible.
910 * @param sci Scintilla widget.
911 * @param line Line.
912 * @param unfold Whether to unfold first.
914 GEANY_API_SYMBOL
915 void sci_goto_line(ScintillaObject *sci, gint line, gboolean unfold)
917 if (unfold) SSM(sci, SCI_ENSUREVISIBLE, (uptr_t) line, 0);
918 SSM(sci, SCI_GOTOLINE, (uptr_t) line, 0);
922 void sci_marker_delete_all(ScintillaObject *sci, gint marker)
924 SSM(sci, SCI_MARKERDELETEALL, (uptr_t) marker, 0);
928 /** Gets style ID at @a position.
929 * @param sci Scintilla widget.
930 * @param position Position.
931 * @return Style ID. */
932 GEANY_API_SYMBOL
933 gint sci_get_style_at(ScintillaObject *sci, gint position)
935 return (gint) SSM(sci, SCI_GETSTYLEAT, (uptr_t) position, 0);
939 void sci_set_codepage(ScintillaObject *sci, gint cp)
941 g_return_if_fail(cp == 0 || cp == SC_CP_UTF8);
942 SSM(sci, SCI_SETCODEPAGE, (uptr_t) cp, 0);
946 void sci_assign_cmdkey(ScintillaObject *sci, gint key, gint command)
948 SSM(sci, SCI_ASSIGNCMDKEY, (uptr_t) key, command);
952 void sci_clear_cmdkey(ScintillaObject *sci, gint key)
954 SSM(sci, SCI_CLEARCMDKEY, (uptr_t) key, 0);
958 /** Gets text between @a start and @a end.
959 * @deprecated sci_get_text_range is deprecated and should not be used in newly-written code.
960 * Use sci_get_contents_range() instead.
962 * @param sci Scintilla widget.
963 * @param start Start.
964 * @param end End.
965 * @param text Text will be zero terminated and must be allocated (end - start + 1) bytes. */
966 GEANY_API_SYMBOL
967 void sci_get_text_range(ScintillaObject *sci, gint start, gint end, gchar *text)
969 struct Sci_TextRange tr;
970 tr.chrg.cpMin = start;
971 tr.chrg.cpMax = end;
972 tr.lpstrText = text;
973 SSM(sci, SCI_GETTEXTRANGE, 0, (long) &tr);
977 /** Gets text between @a start and @a end.
978 * @param sci Scintilla widget.
979 * @param start Start position.
980 * @param end End position.
981 * @return The text inside the given range. Should be freed when no longer needed.
983 * @since 0.17
985 GEANY_API_SYMBOL
986 gchar *sci_get_contents_range(ScintillaObject *sci, gint start, gint end)
988 gchar *text;
990 g_return_val_if_fail(start < end, NULL);
992 text = g_malloc((gsize) (end - start) + 1);
993 sci_get_text_range(sci, start, end, text);
994 return text;
998 void sci_line_duplicate(ScintillaObject *sci)
1000 SSM(sci, SCI_LINEDUPLICATE, 0, 0);
1004 void sci_selection_duplicate(ScintillaObject *sci)
1006 SSM(sci, SCI_SELECTIONDUPLICATE, 0, 0);
1010 /** Inserts text.
1011 * @param sci Scintilla widget.
1012 * @param pos Position, or -1 for current.
1013 * @param text Text. */
1014 GEANY_API_SYMBOL
1015 void sci_insert_text(ScintillaObject *sci, gint pos, const gchar *text)
1017 SSM(sci, SCI_INSERTTEXT, (uptr_t) pos, (sptr_t) text);
1021 GEANY_API_SYMBOL
1022 void sci_set_target_start(ScintillaObject *sci, gint start)
1024 SSM(sci, SCI_SETTARGETSTART, (uptr_t) start, 0);
1028 GEANY_API_SYMBOL
1029 void sci_set_target_end(ScintillaObject *sci, gint end)
1031 SSM(sci, SCI_SETTARGETEND, (uptr_t) end, 0);
1035 GEANY_API_SYMBOL
1036 gint sci_replace_target(ScintillaObject *sci, const gchar *text, gboolean regex)
1038 return (gint) SSM(sci, (regex) ? SCI_REPLACETARGETRE : SCI_REPLACETARGET, (uptr_t) -1, (sptr_t) text);
1042 void sci_set_keywords(ScintillaObject *sci, guint k, const gchar *text)
1044 SSM(sci, SCI_SETKEYWORDS, k, (sptr_t) text);
1048 void sci_set_readonly(ScintillaObject *sci, gboolean readonly)
1050 SSM(sci, SCI_SETREADONLY, readonly != FALSE, 0);
1054 /** Sends Scintilla commands without any parameters.
1055 * @param sci The Scintilla @c GtkWidget.
1056 * @param cmd @c SCI_COMMAND.
1057 * @see http://scintilla.org for the documentation.
1059 * @since 0.16
1061 GEANY_API_SYMBOL
1062 void sci_send_command(ScintillaObject *sci, gint cmd)
1064 SSM(sci, cmd, 0, 0);
1068 /** Gets current line number.
1069 * @param sci Scintilla widget.
1070 * @return Line number. */
1071 GEANY_API_SYMBOL
1072 gint sci_get_current_line(ScintillaObject *sci)
1074 return (gint) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) SSM(sci, SCI_GETCURRENTPOS, 0, 0), 0);
1078 /* Get number of lines partially or fully selected.
1079 * Returns 1 if there is a partial selection on the same line.
1080 * Returns 2 if a whole line is selected including the line break char(s). */
1081 gint sci_get_lines_selected(ScintillaObject *sci)
1083 gint start = (gint) SSM(sci, SCI_GETSELECTIONSTART, 0, 0);
1084 gint end = (gint) SSM(sci, SCI_GETSELECTIONEND, 0, 0);
1085 gint line_start;
1086 gint line_end;
1088 if (start == end)
1089 return 0; /* no selection */
1091 line_start = (gint) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) start, 0);
1092 line_end = (gint) SSM(sci, SCI_LINEFROMPOSITION, (uptr_t) end, 0);
1094 return line_end - line_start + 1;
1098 gint sci_get_first_visible_line(ScintillaObject *sci)
1100 return (gint) SSM(sci, SCI_GETFIRSTVISIBLELINE, 0, 0);
1105 * Sets the current indicator. This is necessary to define an indicator for a range of text or
1106 * clearing indicators for a range of text.
1108 * @param sci Scintilla widget.
1109 * @param indic The indicator number to set.
1111 * @see sci_indicator_clear
1113 * @since 0.16
1115 GEANY_API_SYMBOL
1116 void sci_indicator_set(ScintillaObject *sci, gint indic)
1118 SSM(sci, SCI_SETINDICATORCURRENT, (uptr_t) indic, 0);
1122 void sci_indicator_fill(ScintillaObject *sci, gint pos, gint len)
1124 SSM(sci, SCI_INDICATORFILLRANGE, (uptr_t) pos, len);
1129 * Clears the currently set indicator from a range of text.
1130 * Starting at @a pos, @a len characters long.
1131 * In order to make this function properly, you need to set the current indicator before with
1132 * @ref sci_indicator_set().
1134 * @param sci Scintilla widget.
1135 * @param pos Starting position.
1136 * @param len Length.
1138 * @since 0.16
1140 GEANY_API_SYMBOL
1141 void sci_indicator_clear(ScintillaObject *sci, gint pos, gint len)
1143 SSM(sci, SCI_INDICATORCLEARRANGE, (uptr_t) pos, len);
1147 void sci_select_all(ScintillaObject *sci)
1149 SSM(sci, SCI_SELECTALL, 0, 0);
1153 gint sci_get_line_indent_position(ScintillaObject *sci, gint line)
1155 return (gint) SSM(sci, SCI_GETLINEINDENTPOSITION, (uptr_t) line, 0);
1159 void sci_set_autoc_max_height(ScintillaObject *sci, gint val)
1161 SSM(sci, SCI_AUTOCSETMAXHEIGHT, (uptr_t) val, 0);
1165 /** Finds a matching brace at @a pos.
1166 * @param sci Scintilla widget.
1167 * @param pos Position.
1168 * @return Matching brace position.
1170 * @since 0.15
1172 GEANY_API_SYMBOL
1173 gint sci_find_matching_brace(ScintillaObject *sci, gint pos)
1175 return (gint) SSM(sci, SCI_BRACEMATCH, (uptr_t) pos, 0);
1179 gint sci_get_overtype(ScintillaObject *sci)
1181 return (gint) SSM(sci, SCI_GETOVERTYPE, 0, 0);
1185 void sci_set_tab_indents(ScintillaObject *sci, gboolean set)
1187 SSM(sci, SCI_SETTABINDENTS, set != FALSE, 0);
1191 void sci_set_use_tabs(ScintillaObject *sci, gboolean set)
1193 SSM(sci, SCI_SETUSETABS, set != FALSE, 0);
1197 gint sci_get_pos_at_line_sel_start(ScintillaObject *sci, gint line)
1199 return (gint) SSM(sci, SCI_GETLINESELSTARTPOSITION, (uptr_t) line, 0);
1203 gint sci_get_pos_at_line_sel_end(ScintillaObject *sci, gint line)
1205 return (gint) SSM(sci, SCI_GETLINESELENDPOSITION, (uptr_t) line, 0);
1209 /** Gets selection mode.
1210 * @param sci Scintilla widget.
1211 * @return Selection mode. */
1212 GEANY_API_SYMBOL
1213 gint sci_get_selection_mode(ScintillaObject *sci)
1215 return (gint) SSM(sci, SCI_GETSELECTIONMODE, 0, 0);
1219 /** Sets selection mode.
1220 * @param sci Scintilla widget.
1221 * @param mode Mode. */
1222 GEANY_API_SYMBOL
1223 void sci_set_selection_mode(ScintillaObject *sci, gint mode)
1225 SSM(sci, SCI_SETSELECTIONMODE, (uptr_t) mode, 0);
1229 void sci_set_scrollbar_mode(ScintillaObject *sci, gboolean visible)
1231 SSM(sci, SCI_SETHSCROLLBAR, visible != FALSE, 0);
1232 SSM(sci, SCI_SETVSCROLLBAR, visible != FALSE, 0);
1236 /** Sets the indentation of a line.
1237 * @param sci Scintilla widget.
1238 * @param line Line to indent.
1239 * @param indent Indentation width.
1241 * @since 0.19
1243 GEANY_API_SYMBOL
1244 void sci_set_line_indentation(ScintillaObject *sci, gint line, gint indent)
1246 SSM(sci, SCI_SETLINEINDENTATION, (uptr_t) line, indent);
1250 /** Gets the indentation width of a line.
1251 * @param sci Scintilla widget.
1252 * @param line Line to get the indentation from.
1253 * @return Indentation width.
1255 * @since 0.19
1257 GEANY_API_SYMBOL
1258 gint sci_get_line_indentation(ScintillaObject *sci, gint line)
1260 return (gint) SSM(sci, SCI_GETLINEINDENTATION, (uptr_t) line, 0);
1264 void sci_set_caret_policy_x(ScintillaObject *sci, gint policy, gint slop)
1266 SSM(sci, SCI_SETXCARETPOLICY, (uptr_t) policy, slop);
1270 void sci_set_caret_policy_y(ScintillaObject *sci, gint policy, gint slop)
1272 SSM(sci, SCI_SETYCARETPOLICY, (uptr_t) policy, slop);
1276 void sci_set_scroll_stop_at_last_line(ScintillaObject *sci, gboolean set)
1278 SSM(sci, SCI_SETENDATLASTLINE, set != FALSE, 0);
1282 void sci_cancel(ScintillaObject *sci)
1284 SSM(sci, SCI_CANCEL, 0, 0);
1288 gint sci_get_position_after(ScintillaObject *sci, gint start)
1290 return (gint) SSM(sci, SCI_POSITIONAFTER, (uptr_t) start, 0);
1294 void sci_lines_join(ScintillaObject *sci)
1296 SSM(sci, SCI_LINESJOIN, 0, 0);
1300 gint sci_text_width(ScintillaObject *sci, gint styleNumber, const gchar *text)
1302 return (gint) SSM(sci, SCI_TEXTWIDTH, (uptr_t) styleNumber, (sptr_t) text);
1306 void sci_move_selected_lines_down(ScintillaObject *sci)
1308 SSM(sci, SCI_MOVESELECTEDLINESDOWN, 0, 0);
1312 void sci_move_selected_lines_up(ScintillaObject *sci)
1314 SSM(sci, SCI_MOVESELECTEDLINESUP, 0, 0);
1318 gint sci_word_start_position(ScintillaObject *sci, gint position, gboolean onlyWordCharacters)
1320 return SSM(sci, SCI_WORDSTARTPOSITION, position, onlyWordCharacters);
1324 gint sci_word_end_position(ScintillaObject *sci, gint position, gboolean onlyWordCharacters)
1326 return SSM(sci, SCI_WORDENDPOSITION, position, onlyWordCharacters);